|
1 | 1 | """Utility functions for the LLM Change Agent."""
|
2 | 2 |
|
3 |
| -import os |
4 |
| -from pathlib import Path |
5 | 3 | from typing import Union
|
6 | 4 |
|
7 | 5 | import yaml
|
8 | 6 | from langchain.agents import AgentExecutor
|
9 | 7 | from langchain.agents.react.agent import create_react_agent
|
10 | 8 | from langchain.tools.retriever import create_retriever_tool
|
11 | 9 | from langchain_chroma import Chroma
|
| 10 | +from langchain_community.document_loaders import WebBaseLoader |
12 | 11 | from langchain_core.documents import Document
|
13 | 12 | from langchain_openai import OpenAIEmbeddings
|
14 | 13 | from langchain_text_splitters import RecursiveCharacterTextSplitter
|
15 | 14 | from openai import OpenAI
|
16 |
| -from langchain_community.document_loaders import WebBaseLoader |
17 |
| - |
18 | 15 |
|
19 | 16 | from llm_change_agent.config.llm_config import AnthropicConfig, CBORGConfig, LLMConfig, OllamaConfig, OpenAIConfig
|
20 | 17 | from llm_change_agent.constants import (
|
@@ -197,22 +194,26 @@ def split_documents(document: Union[str, Document]):
|
197 | 194 |
|
198 | 195 | def execute_agent(llm, prompt):
|
199 | 196 | """Create a retriever agent."""
|
| 197 | + grammar = get_kgcl_grammar() |
| 198 | + # schema = get_kgcl_schema() |
| 199 | + # docs_list = ( |
| 200 | + # split_documents(str(schema)) + split_documents(grammar["lark"]) + split_documents(grammar["explanation"]) |
| 201 | + # ) |
| 202 | + grammar_docs_list = split_documents(grammar["lark"]) + split_documents(grammar["explanation"]) |
200 | 203 | if VECTO_DB_PATH.exists():
|
201 |
| - vectorstore = Chroma(embedding=OpenAIEmbeddings(show_progress_bar=True), persist_directory=str(VECTOR_STORE)) |
| 204 | + vectorstore = Chroma( |
| 205 | + embedding_function=OpenAIEmbeddings(show_progress_bar=True), persist_directory=str(VECTOR_STORE) |
| 206 | + ) |
202 | 207 | else:
|
203 |
| - grammar = get_kgcl_grammar() |
204 |
| - # schema = get_kgcl_schema() |
205 |
| - # docs_list = ( |
206 |
| - # split_documents(str(schema)) + split_documents(grammar["lark"]) + split_documents(grammar["explanation"]) |
207 |
| - # ) |
208 |
| - grammar_docs_list = split_documents(grammar["lark"]) + split_documents(grammar["explanation"]) |
209 | 208 |
|
210 | 209 | list_of_doc_lists = [WebBaseLoader(url, show_progress=True).load() for url in ONTODIFF_DOCS]
|
211 | 210 | diff_docs_list = [split_doc for docs in list_of_doc_lists for doc in docs for split_doc in split_documents(doc)]
|
212 | 211 | docs_list = grammar_docs_list + diff_docs_list
|
213 | 212 |
|
214 |
| - vectorstore = Chroma.from_documents(documents=docs_list, embedding=OpenAIEmbeddings(show_progress_bar=True), persist_directory=str(VECTOR_STORE)) |
215 |
| - vectorstore.persist() |
| 213 | + vectorstore = Chroma.from_documents( |
| 214 | + documents=docs_list, embedding=OpenAIEmbeddings(show_progress_bar=True), persist_directory=str(VECTOR_STORE) |
| 215 | + ) |
| 216 | + |
216 | 217 | retriever = vectorstore.as_retriever(search_kwargs={"k": 1})
|
217 | 218 | tool = create_retriever_tool(retriever, "change_agent_retriever", "Change Agent Retriever")
|
218 | 219 | tools = [tool]
|
|
0 commit comments