oluinioluwa814 commited on
Commit
d20d8ca
·
verified ·
1 Parent(s): 4b3fc6c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -0
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import os
3
+
4
+ from langchain_openai import ChatOpenAI, OpenAIEmbeddings
5
+ from langchain_astradb import AstraDBVectorStore
6
+ from langchain.agents import create_tool_calling_agent
7
+ from langchain.tools.retriever import create_retriever_tool
8
+ from langchain.agents import AgentExecutor
9
+ from github import fetch_github_issues
10
+ import gradio as gr
11
+ from langchain import hub
12
+ from note import note_tool
13
+
14
+ load_dotenv()
15
+
16
+ def connet_to_vstore():
17
+ embeddings = OpenAIEmbeddings()
18
+ desire_namespace = os.getenv("ASTRA_DB_KEYSPACE")
19
+ ASTRA_DB_APPLICATION_TOKEN = os.getenv("ASTRA_DB_APPLICATION_TOKEN")
20
+ ASTRA_DB_API_ENDPOINT = os.getenv("ASTRA_DB_API_ENDPOINT")
21
+ if desire_namespace:
22
+ ASTRA_DB_KEYSPACE = desire_namespace
23
+ else:
24
+ ASTRA_DB_KEYSPACE = None
25
+
26
+ vstore = AstraDBVectorStore(
27
+ embedding=embeddings,
28
+ collection_name="github",
29
+ namespace=ASTRA_DB_KEYSPACE,
30
+ api_endpoint=ASTRA_DB_API_ENDPOINT,
31
+ token=ASTRA_DB_APPLICATION_TOKEN,
32
+ )
33
+ return vstore
34
+
35
+ vstore = connet_to_vstore()
36
+ add_to_vectorstore = input("Do you want to update the issue? (yes/no): ").lower() in ["yes", "y"]
37
+ if add_to_vectorstore:
38
+ owner = "Ini-design"
39
+ repo = "register"
40
+ issues = fetch_github_issues(owner, repo)
41
+ try:
42
+ vstore.delete_collection()
43
+ except:
44
+ pass
45
+
46
+ vstore = connet_to_vstore()
47
+ vstore.add_documents(issues)
48
+
49
+ # results = vstore.similarity_search('flash message', k=3)
50
+ # for res in results:
51
+ # print(f"*{res.page_content} {res.metadata}")
52
+
53
+ retriever = vstore.as_retriever(search_kwargs={"k":3})
54
+ retriever_tool = create_retriever_tool(
55
+ retriever,
56
+ "github_search",
57
+ "search for information aabout github issues. For any question abour github issue, you must used this tools!"
58
+ )
59
+
60
+ prompt = hub.pull("hwchase17/openai-functions_agent")
61
+ llm = ChatOpenAI()
62
+
63
+ tools = [retriever_tool], note_tool
64
+ agent = create_tool_calling_agent(llm, tools, prompt)
65
+ agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
66
+
67
+ def answer_question(question):
68
+ """Function to process user question and return agent response"""
69
+ if not question.strip():
70
+ return "Please enter a question."
71
+
72
+ try:
73
+ result = agent_executor.invoke({"input": question})
74
+ return result["output"]
75
+ except Exception as e:
76
+ return f"Error: {str(e)}"
77
+
78
+ # Create Gradio Interface
79
+ demo = gr.Interface(
80
+ fn=answer_question,
81
+ inputs=gr.Textbox(
82
+ label="Ask about GitHub Issues",
83
+ placeholder="Type your question here...",
84
+ lines=3
85
+ ),
86
+ outputs=gr.Textbox(
87
+ label="Response",
88
+ lines=5
89
+ ),
90
+ title="GitHub Issues AI Agent",
91
+ description="Ask questions about GitHub issues using AI-powered semantic search",
92
+ examples=[
93
+ ["What are the recent issues?"],
94
+ ["Tell me about bug reports"],
95
+ ["What features are being requested?"]
96
+ ],
97
+ allow_flagging="never"
98
+ )
99
+
100
+ if __name__ == "__main__":
101
+ demo.launch(debug=False)