Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Agent framework] Remove langchain dependency #29

Merged
merged 6 commits into from
Dec 4, 2023
Merged
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
3 changes: 0 additions & 3 deletions common/constants/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export const ASSISTANT_API = {
SEND_MESSAGE: `${API_BASE}/send_message`,
SESSION: `${API_BASE}/session`,
SESSIONS: `${API_BASE}/sessions`,
PPL_GENERATOR: `${API_BASE}/generate_ppl`,
SUMMARIZATION: `${API_BASE}/summarize`,
AGENT_TEST: `${API_BASE}/agent_test`,
FEEDBACK: `${API_BASE}/feedback`,
ABORT_AGENT_EXECUTION: `${API_BASE}/abort`,
REGENERATE: `${API_BASE}/regenerate`,
Expand Down
176 changes: 0 additions & 176 deletions common/utils/llm_chat/__tests__/traces.test.ts

This file was deleted.

63 changes: 0 additions & 63 deletions common/utils/llm_chat/traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Run } from 'langchain/callbacks';
import { AgentRun } from 'langchain/dist/callbacks/handlers/tracer';
import _ from 'lodash';

export interface AgentFrameworkTrace {
interactionId: string;
parentInteractionId: string;
Expand All @@ -16,62 +12,3 @@ export interface AgentFrameworkTrace {
origin: string;
traceNumber: number;
}

export interface LangchainTrace {
id: Run['id'];
parentRunId?: Run['parent_run_id'];
actions?: AgentRun['actions'];
type: Run['run_type'];
startTime: Run['start_time'];
name: string;
input: string;
output?: string;
}

const getValue = (obj: Record<string, string>, possibleKeys: string[]) => {
for (const key of possibleKeys) {
const value = _.get(obj, key);
if (value) return value;
}
return '';
};

/**
* By default, tool traces have name 'DynamicTool'. Replace name for all tool
* traces with the tool used in parent run actions.
*/
const replaceToolNames = (traces: LangchainTrace[]) => {
return traces.map((trace) => ({
...trace,
...(trace.type === 'tool' && {
name: _.get(
traces.find((t) => t.id === trace.parentRunId),
'actions.0.tool',
trace.name
),
}),
}));
};

const traverse = (runs: Array<Run | AgentRun>, traces: LangchainTrace[] = []) => {
traces.push(
...runs.map((run) => ({
id: run.id,
parentRunId: run.parent_run_id,
type: run.run_type,
startTime: run.start_time,
name: run.name,
input: getValue(run.inputs, ['input', 'question', 'messages.0.0.kwargs.content']),
output: run.outputs && getValue(run.outputs, ['output', 'text', 'generations.0.0.text']),
...('actions' in run && { actions: run.actions }),
}))
);
runs.forEach((run) => {
if (run.child_runs) traverse(run.child_runs, traces);
});
return traces;
};

export const convertToTraces = (runs: Run[]) => {
return replaceToolNames(traverse(runs));
};
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"csv-parser": "^3.0.0",
"dompurify": "^2.4.1",
wanglam marked this conversation as resolved.
Show resolved Hide resolved
"jsdom": "^22.1.0",
"langchain": "^0.0.164",
"postinstall": "^0.7.4",
"web-streams-polyfill": "^3.2.1"
"postinstall": "^0.7.4"
},
"devDependencies": {
"@types/autosize": "^4.0.1",
Expand Down
100 changes: 0 additions & 100 deletions public/components/langchain_traces.tsx

This file was deleted.

Loading
Loading