Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
isamu committed Jan 13, 2025
1 parent c886926 commit 3cab1ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions llm_agents/openai_agent/lib/openai_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,37 @@ exports.openAIMockAgent = exports.openAIAgent = void 0;
const openai_1 = __importDefault(require("openai"));
const graphai_1 = require("graphai");
const llm_utils_1 = require("@graphai/llm_utils");
const convToolCall = (tool_call) => {
return {
id: tool_call.id,
name: tool_call.function.name,
arguments: (() => {
try {
return JSON.parse(tool_call.function.arguments);
}
catch (__e) {
console.log(__e);
return undefined;
}
})(),
};
};
const convertOpenAIChatCompletion = (response, messages) => {
const message = response?.choices[0] && response?.choices[0].message ? response?.choices[0].message : null;
const text = message && message.content ? message.content : null;
const functionResponse = message?.tool_calls && message?.tool_calls[0] ? message?.tool_calls[0] : null;
const functionResponses = message?.tool_calls && Array.isArray(message?.tool_calls) ? message?.tool_calls : [];
const functionResponse = functionResponses[0] ? functionResponses[0] : null;
// const functionId = message?.tool_calls && message?.tool_calls[0] ? message?.tool_calls[0]?.id : null;
const tool = functionResponse
? {
id: functionResponse.id,
name: functionResponse?.function?.name,
arguments: (() => {
try {
return JSON.parse(functionResponse?.function?.arguments);
}
catch (__e) {
return undefined;
}
})(),
}
: undefined;
const tool = functionResponse ? convToolCall(functionResponse) : undefined;
const tool_calls = functionResponses.map(convToolCall);
if (message) {
messages.push(message);
}
return {
...response,
text,
tool,
tool_calls,
message,
messages,
};
Expand Down
2 changes: 1 addition & 1 deletion llm_agents/openai_agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphai/openai_agent",
"version": "0.2.2",
"version": "0.2.3",
"description": "OpenAI agents for GraphAI.",
"main": "lib/index.js",
"files": [
Expand Down

0 comments on commit 3cab1ac

Please sign in to comment.