Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions tests/dotnet/azure-openai/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,13 @@ static async Task RunPrototype()
};
options.Tools.Add(weatherTool);

// Derive from options.Tools — the same collection passed to CompleteChatAsync (OpenAI function-calling format)
var toolDefinitionsJson = JsonSerializer.Serialize(
options.Tools.Select(t => new Dictionary<string, object>
{
["type"] = "function",
["function"] = new
{
name = t.FunctionName,
description = t.FunctionDescription,
parameters = JsonSerializer.Deserialize<JsonElement>(t.FunctionParameters)
}
["name"] = t.FunctionName,
["description"] = t.FunctionDescription,
["parameters"] = JsonSerializer.Deserialize<JsonElement>(t.FunctionParameters)
}).ToArray()
);
activity?.SetTag("gen_ai.operation.name", "chat");
Expand Down
10 changes: 3 additions & 7 deletions tests/dotnet/extensions-ai/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,13 @@ static async Task RunPrototype()
};
options.Tools.Add(weatherTool);

// Derive from options.Tools — the same collection passed to CompleteChatAsync (OpenAI function-calling format)
var toolDefinitionsJson = JsonSerializer.Serialize(
options.Tools.Select(t => new Dictionary<string, object>
{
["type"] = "function",
["function"] = new
{
name = t.FunctionName,
description = t.FunctionDescription,
parameters = JsonSerializer.Deserialize<JsonElement>(t.FunctionParameters)
}
["name"] = t.FunctionName,
["description"] = t.FunctionDescription,
["parameters"] = JsonSerializer.Deserialize<JsonElement>(t.FunctionParameters)
}).ToArray()
);
activity?.SetTag("gen_ai.operation.name", "chat");
Expand Down
25 changes: 10 additions & 15 deletions tests/dotnet/semantic-kernel/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,23 @@ static async Task RunPrototype()
using (var activity = s_manualActivitySource.StartActivity("chat gpt-4o-mini"))
{
var endpoint = new Uri(mockBaseUrl);
// Semantic Kernel converts plugins to OpenAI function-calling format
// before sending to the API, so we mirror that shape here.
var toolDefinitionsJson = JsonSerializer.Serialize(
kernel.Plugins
.SelectMany(p => p)
.Select(f => new Dictionary<string, object>
{
["type"] = "function",
["function"] = new
["name"] = f.Name,
["description"] = f.Description,
["parameters"] = new
{
name = f.Name,
description = f.Description,
parameters = new
{
type = "object",
properties = f.Metadata.Parameters.ToDictionary(
p => p.Name,
p => new { type = ToJsonSchemaType(p.ParameterType) }),
required = f.Metadata.Parameters
.Where(p => p.IsRequired)
.Select(p => p.Name)
}
type = "object",
properties = f.Metadata.Parameters.ToDictionary(
p => p.Name,
p => new { type = ToJsonSchemaType(p.ParameterType) }),
required = f.Metadata.Parameters
.Where(p => p.IsRequired)
.Select(p => p.Name)
}
}));
activity?.SetTag("gen_ai.operation.name", "chat");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ static void runConverseToolCall(BedrockRuntimeClient client) {
ToolConfiguration toolConfig = ToolConfiguration.builder()
.tools(Tool.builder().toolSpec(toolSpec).build())
.build();
String toolDefinitionsJson = "[{\"toolSpec\":{\"name\":\"get_weather\",\"description\":\"Get the current weather\"," +
"\"inputSchema\":{\"json\":{\"type\":\"object\",\"properties\":{\"location\":{\"type\":\"string\"," +
"\"description\":\"City name\"}},\"required\":[\"location\"]}}}}]";
String toolDefinitionsJson = "[{\"type\":\"function\",\"name\":\"get_weather\",\"description\":\"Get the current weather\"," +
"\"parameters\":{\"type\":\"object\",\"properties\":{\"location\":{\"type\":\"string\"," +
"\"description\":\"City name\"}},\"required\":[\"location\"]}}]";
Span span = tracer.spanBuilder("chat " + modelId).startSpan();
try {
try (var scope = span.makeCurrent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,18 @@ static void runChatToolCall(OpenAIClient client) {
.build())
.build())
.build();
// Derive from params.tools() — the same tools passed to the API call
String toolDefinitionsJson;
try {
toolDefinitionsJson = ObjectMappers.jsonMapper().writeValueAsString(params.tools().orElse(List.of()));
var toolDefs = params.tools().orElse(List.of()).stream().map(tool -> {
var fn = tool.asFunction().function();
var def = new java.util.LinkedHashMap<String, Object>();
def.put("type", "function");
def.put("name", fn.name());
fn.description().ifPresent(d -> def.put("description", d));
fn.parameters().ifPresent(p -> def.put("parameters", p));
return def;
}).toList();
toolDefinitionsJson = ObjectMappers.jsonMapper().writeValueAsString(toolDefs);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Expand Down
7 changes: 6 additions & 1 deletion tests/js/anthropic/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ async function main() {
span.setAttribute("gen_ai.provider.name", "anthropic");
span.setAttribute("gen_ai.request.model", requestModel);
span.setAttribute("gen_ai.request.max_tokens", requestMaxTokens);
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([requestTool]));
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([{
type: "function",
name: requestTool.name,
description: requestTool.description,
parameters: requestTool.input_schema,
}]));
const resp = await client.messages.create({
model: requestModel,
max_tokens: requestMaxTokens,
Expand Down
7 changes: 6 additions & 1 deletion tests/js/aws-bedrock/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ async function main() {
},
};
const toolConfig = { tools: [toolSpec] };
span.setAttribute("gen_ai.tool.definitions", JSON.stringify(toolConfig.tools));
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([{
type: "function",
name: toolSpec.toolSpec.name,
description: toolSpec.toolSpec.description,
parameters: toolSpec.toolSpec.inputSchema.json,
}]));
const messages = [
{ role: "user" as const, content: [{ text: "What's the weather in Seattle?" }] },
];
Expand Down
7 changes: 6 additions & 1 deletion tests/js/azure-openai/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ async function main() {
span.setAttribute("gen_ai.operation.name", "chat");
span.setAttribute("gen_ai.provider.name", "openai");
span.setAttribute("gen_ai.request.model", requestModel);
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([requestTool]));
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([{
type: requestTool.type,
name: requestTool.function.name,
description: requestTool.function.description,
parameters: requestTool.function.parameters,
}]));
span.setAttribute("server.address", endpoint.hostname);
if (endpoint.port) {
span.setAttribute("server.port", Number(endpoint.port));
Expand Down
13 changes: 12 additions & 1 deletion tests/js/cohere/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,18 @@ async function main() {
location: { description: "City name", type: "str" as const, required: true },
},
};
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([requestTool]));
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([{
type: "function",
name: requestTool.name,
description: requestTool.description,
parameters: {
type: "object",
properties: Object.fromEntries(
Object.entries(requestTool.parameterDefinitions).map(([k, v]: [string, any]) => [k, { type: v.type, description: v.description }])
),
required: Object.entries(requestTool.parameterDefinitions).filter(([, v]: [string, any]) => v.required).map(([k]) => k),
},
}]));
const resp = await client.chat({
model: requestModel,
message: "What's the weather in Seattle?",
Expand Down
3 changes: 1 addition & 2 deletions tests/js/langchain/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ async function main() {
}),
},
];
// Derive from the same tools array passed to bindTools (LangChain StructuredToolParams format)
span.setAttribute(
"gen_ai.tool.definitions",
JSON.stringify(tools.map((t) => ({ name: t.name, description: t.description, schema: toJSONSchema(t.schema) }))),
JSON.stringify(tools.map((t) => ({ type: "function", name: t.name, description: t.description, parameters: toJSONSchema(t.schema) }))),
);

const llmWithTools = llm.bindTools(tools, { tool_choice: "auto" });
Expand Down
7 changes: 6 additions & 1 deletion tests/js/llamaindex/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ async function main() {
},
},
};
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([requestTool]));
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([{
type: requestTool.type,
name: requestTool.function.name,
description: requestTool.function.description,
parameters: requestTool.function.parameters,
}]));
const resp = await llm.chat({
messages: [{ role: "user", content: "What's the weather in Seattle?" }],
additionalChatOptions: { tools: [requestTool] },
Expand Down
7 changes: 6 additions & 1 deletion tests/js/openai/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ async function main() {
span.setAttribute("gen_ai.operation.name", "chat");
span.setAttribute("gen_ai.provider.name", "openai");
span.setAttribute("gen_ai.request.model", requestModel);
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([requestTool]));
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([{
type: requestTool.type,
name: requestTool.function.name,
description: requestTool.function.description,
parameters: requestTool.function.parameters,
}]));
span.setAttribute("server.address", endpoint.hostname);
if (endpoint.port) {
span.setAttribute("server.port", Number(endpoint.port));
Expand Down
3 changes: 2 additions & 1 deletion tests/js/vercel-ai/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ async function main() {
"gen_ai.tool.definitions",
JSON.stringify(
Object.entries(tools).map(([name, t]) => ({
type: "function",
name: name,
description: t.description,
inputSchema: toJSONSchema(t.inputSchema!),
parameters: toJSONSchema(t.inputSchema!),
})),
),
);
Expand Down
9 changes: 8 additions & 1 deletion tests/js/vertexai/test_prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ async function main() {
},
}],
};
span.setAttribute("gen_ai.tool.definitions", JSON.stringify([requestTool]));
span.setAttribute("gen_ai.tool.definitions", JSON.stringify(
requestTool.functionDeclarations.map((fn: any) => ({
type: "function",
name: fn.name,
description: fn.description,
parameters: fn.parameters,
}))
));
const result = await model.generateContent({
contents: [{ role: "user", parts: [{ text: "What's the weather in Seattle?" }] }],
tools: [requestTool],
Expand Down
7 changes: 6 additions & 1 deletion tests/python/anthropic/test_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ def run_chat_tool_call_prototype(client):
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.provider.name", "anthropic")
span.set_attribute("gen_ai.request.model", request_model)
span.set_attribute("gen_ai.tool.definitions", json.dumps([request_tool]))
span.set_attribute("gen_ai.tool.definitions", json.dumps([{
"type": "function",
"name": request_tool["name"],
"description": request_tool["description"],
"parameters": request_tool["input_schema"],
}]))
resp = client.messages.create(
model=request_model,
max_tokens=100,
Expand Down
10 changes: 9 additions & 1 deletion tests/python/autogen/test_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ def run_chat_tool_call_prototype():
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.provider.name", "openai")
span.set_attribute("gen_ai.request.model", request_model)
span.set_attribute("gen_ai.tool.definitions", json.dumps(tools))
span.set_attribute("gen_ai.tool.definitions", json.dumps([
{
"type": t["type"],
"name": t["function"]["name"],
"description": t["function"]["description"],
"parameters": t["function"]["parameters"],
}
for t in tools
]))
if endpoint.hostname:
span.set_attribute("server.address", endpoint.hostname)
if endpoint.port is not None:
Expand Down
7 changes: 6 additions & 1 deletion tests/python/aws-bedrock/test_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ def run_converse_tool_call_prototype(client):
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.provider.name", "aws.bedrock")
span.set_attribute("gen_ai.request.model", request_model)
span.set_attribute("gen_ai.tool.definitions", json.dumps(tool_config["tools"]))
span.set_attribute("gen_ai.tool.definitions", json.dumps([{
"type": "function",
"name": tool_spec["toolSpec"]["name"],
"description": tool_spec["toolSpec"]["description"],
"parameters": tool_spec["toolSpec"]["inputSchema"]["json"],
}]))
messages = [
{
"role": "user",
Expand Down
10 changes: 9 additions & 1 deletion tests/python/azure-ai-foundry/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ def run_invoke_agent(client):
span.set_attribute("gen_ai.agent.id", agent.id)
span.set_attribute("gen_ai.agent.name", agent.name or "")
span.set_attribute("gen_ai.request.model", AGENT_MODEL)
span.set_attribute("gen_ai.tool.definitions", json.dumps(tool_defs))
span.set_attribute("gen_ai.tool.definitions", json.dumps([
{
"type": t["type"],
"name": t["function"]["name"],
"description": t["function"]["description"],
"parameters": t["function"]["parameters"],
}
for t in tool_defs
]))
span.set_attribute("server.address", _SERVER_ADDRESS)
span.set_attribute("server.port", _SERVER_PORT)
try:
Expand Down
8 changes: 3 additions & 5 deletions tests/python/azure-ai-inference/test_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ def run_chat_tool_call_prototype(client):
span.set_attribute("gen_ai.request.model", request_model)
span.set_attribute("gen_ai.tool.definitions", json.dumps([{
"type": "function",
"function": {
"name": tool.function.name,
"description": tool.function.description,
"parameters": tool.function.parameters,
},
"name": tool.function.name,
"description": tool.function.description,
"parameters": tool.function.parameters,
}]))
if endpoint.hostname:
span.set_attribute("server.address", endpoint.hostname)
Expand Down
10 changes: 9 additions & 1 deletion tests/python/azure-openai/test_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ def run_chat_tool_call_prototype(client):
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.provider.name", "openai")
span.set_attribute("gen_ai.request.model", request_model)
span.set_attribute("gen_ai.tool.definitions", json.dumps(tools))
span.set_attribute("gen_ai.tool.definitions", json.dumps([
{
"type": t["type"],
"name": t["function"]["name"],
"description": t["function"]["description"],
"parameters": t["function"]["parameters"],
}
for t in tools
]))
if endpoint.hostname:
span.set_attribute("server.address", endpoint.hostname)
if endpoint.port is not None:
Expand Down
10 changes: 9 additions & 1 deletion tests/python/cohere/test_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ def run_chat_tool_call(client):
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.provider.name", "cohere")
span.set_attribute("gen_ai.request.model", request_model)
span.set_attribute("gen_ai.tool.definitions", json.dumps(tools))
span.set_attribute("gen_ai.tool.definitions", json.dumps([
{
"type": t["type"],
"name": t["function"]["name"],
"description": t["function"]["description"],
"parameters": t["function"]["parameters"],
}
for t in tools
]))
resp = client.chat(
model=request_model,
messages=[{"role": "user", "content": "What's the weather in Seattle?"}],
Expand Down
10 changes: 3 additions & 7 deletions tests/python/crewai/test_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,12 @@ def get_weather(location: str) -> str:
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.provider.name", "openai")
span.set_attribute("gen_ai.request.model", request_model)
# CrewAI converts tools to OpenAI function-calling format before
# passing them to litellm, so we mirror that shape here.
span.set_attribute("gen_ai.tool.definitions", json.dumps([
{
"type": "function",
"function": {
"name": t.name,
"description": t.func.__doc__,
"parameters": t.args_schema.model_json_schema(),
},
"name": t.name,
"description": t.func.__doc__,
"parameters": t.args_schema.model_json_schema(),
}
for t in tools
]))
Expand Down
Loading