robinroy03 commited on
Commit
051904a
1 Parent(s): 3cd6138

migrated to new db, improved references

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import discord
2
  import aiohttp
3
 
 
4
  import os
5
  import threading
6
 
@@ -42,7 +43,7 @@ async def llm_output(question: str, context: str) -> str:
42
  # URL_LLM = 'http://localhost:11434' # NOTE: FOR TESTING
43
 
44
  prompt = f"""
45
- You are a senior developer. Answer the users question based on the context provided.
46
 
47
  Question: {question}
48
 
@@ -107,12 +108,26 @@ async def on_message(message):
107
  question = message.content.replace("<@1243428204124045385>", "")
108
 
109
  embedding: list = await embedding_output(question)
 
110
  db_knn: dict = await db_output(embedding)
111
- llm_answer: str = await llm_output(question, db_knn['matches'][0]['metadata']['text']) # for the highest knn result (for the test only right now) TODO: make this better
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
  try:
114
  await message.reply(content=llm_answer[:1990], view=Like_Dislike()) # TODO: handle large responses (>2000)
115
- await message.reply(content=db_knn['matches'][0]['metadata']['text'][:1990]) # TODO: handle large responses (>2000)
116
  except Exception as e: # TODO: make exception handling better
117
  print(e)
118
  await message.reply("An error occurred. Retry again.")
 
1
  import discord
2
  import aiohttp
3
 
4
+ import ast
5
  import os
6
  import threading
7
 
 
43
  # URL_LLM = 'http://localhost:11434' # NOTE: FOR TESTING
44
 
45
  prompt = f"""
46
+ You are a senior FURY developer. FURY is a high level python graphics API similar to VTK.
47
 
48
  Question: {question}
49
 
 
108
  question = message.content.replace("<@1243428204124045385>", "")
109
 
110
  embedding: list = await embedding_output(question)
111
+
112
  db_knn: dict = await db_output(embedding)
113
+ db_context = ""
114
+ references = ""
115
+ for i in range(len(db_knn['matches'])):
116
+ data = db_knn['matches'][i]['metadata']['data']
117
+ db_context += (data + "\n")
118
+ data = ast.literal_eval(data)
119
+ references += ("<https://github.com/fury-gl/fury/tree/master/" + data['path'] + ">")
120
+ if data.get("function_name"):
121
+ references += f"\tFunction Name: {data.get("function_name")}"
122
+ else:
123
+ references += f"\tClass Name: {data.get("class_name")}"
124
+ references += "\n"
125
+
126
+ llm_answer: str = await llm_output(question, db_context) # for the highest knn result (for the test only right now) TODO: make this better
127
 
128
  try:
129
  await message.reply(content=llm_answer[:1990], view=Like_Dislike()) # TODO: handle large responses (>2000)
130
+ await message.reply(content=f"**References**\n{references}")
131
  except Exception as e: # TODO: make exception handling better
132
  print(e)
133
  await message.reply("An error occurred. Retry again.")