|
1 |
| -import json |
2 |
| -from langchain.prompts import ChatPromptTemplate |
3 |
| -from langchain.output_parsers import ResponseSchema, StructuredOutputParser |
4 |
| -import re |
5 |
| - |
| 1 | +from langchain.chains import ConversationalRetrievalChain |
| 2 | +from langchain.agents import Tool |
| 3 | +from langchain.tools import DuckDuckGoSearchRun |
| 4 | +from langchain.agents import initialize_agent |
6 | 5 | from lazygitgpt.llms import chat_model
|
7 | 6 | from lazygitgpt.datasources.repos import read_repository_contents
|
8 | 7 | from lazygitgpt.git.operations import update_files
|
| 8 | +from lazygitgpt.retrievers.retrievalqa import retriever |
| 9 | +from lazygitgpt.memory.memory import memory |
| 10 | + |
| 11 | +search = DuckDuckGoSearchRun() |
| 12 | + |
| 13 | +def generate_response(prompt): |
| 14 | + inputs = {'chat_history': '', 'question': prompt} |
| 15 | + qa = ConversationalRetrievalChain.from_llm(chat_model, retriever=retriever, memory=memory) |
| 16 | + result = qa(inputs) |
| 17 | + return result["answer"] |
| 18 | + |
| 19 | +# tools = [ |
| 20 | +# Tool( |
| 21 | +# name='DuckDuckGo Search', |
| 22 | +# func= search.run, |
| 23 | +# description="Useful for when you need to do a search on the internet to find information that another tool can't find. be specific with your input." |
| 24 | +# ), |
| 25 | +# Tool( |
| 26 | +# name='Conversational Retrieval', |
| 27 | +# func=generate_response, |
| 28 | +# description="This is Conversational Retrieval chain which has content of the entire repository." |
| 29 | +# ) |
| 30 | +# ] |
9 | 31 |
|
10 |
| -output_schema = ResponseSchema(name='filename', description='contents', type='string') |
11 |
| -output_parser = StructuredOutputParser(response_schemas=[output_schema]) |
12 |
| -format_instructions = output_parser.get_format_instructions() |
13 |
| -template_string = """You are an expert programmer. |
14 |
| -You are reviewing a code repository. |
15 |
| -Read the code and make changes to the code as per the user requirements. |
16 |
| -user requirements: {user_requirements} |
17 |
| -code repository: {code_repository} |
18 |
| -Output the contents of the file that you changed as per the format instructions : {format_instructions} |
19 |
| -""" |
| 32 | +# zero_shot_agent = initialize_agent( |
| 33 | +# agent="zero-shot-react-description", |
| 34 | +# tools=tools, |
| 35 | +# llm=chat_model, |
| 36 | +# verbose=True, |
| 37 | +# max_iterations=30, |
| 38 | +# retriever=retriever |
| 39 | +# ) |
20 | 40 |
|
21 |
| -def generate_response(prompt, sources=read_repository_contents()): |
22 |
| - sources_str = json.dumps(sources, indent=4) |
23 |
| - prompt_template = ChatPromptTemplate.from_template(template_string) |
24 |
| - messages = prompt_template.format_messages(user_requirements = prompt, |
25 |
| - code_repository = sources_str, |
26 |
| - format_instructions=format_instructions) |
27 |
| - response = chat_model(messages) |
28 |
| - response_json = response.to_json() |
29 |
| - data = response_json['kwargs']['content'] |
30 |
| - return data |
| 41 | +# def run(prompt): |
| 42 | +# reponse = zero_shot_agent.run(prompt) |
| 43 | +# return reponse |
0 commit comments