Skip to content

Commit

Permalink
[Agent framework] Remove langchain dependency (#29)
Browse files Browse the repository at this point in the history
* feat: remove langchain related codes

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: remove langchain related code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: remove dependency of langchain

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: remove useless code and config

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: add missing file

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: remove useless client

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Dec 5, 2023
1 parent 2680dce commit 1054c65
Show file tree
Hide file tree
Showing 82 changed files with 69 additions and 5,746 deletions.
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",
"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

0 comments on commit 1054c65

Please sign in to comment.