Prakhar Bhandari commited on
Commit
f253677
·
1 Parent(s): 435affe

Updated query classification

Browse files
Files changed (1) hide show
  1. kg_builder/src/main.py +10 -3
kg_builder/src/main.py CHANGED
@@ -15,12 +15,19 @@ def get_llm():
15
  def classify_query(query):
16
  llm = get_llm()
17
  try:
18
- response = llm.ChatCompletion.create(
19
  model="gpt-3.5-turbo-16k",
20
- messages=[{"role": "user", "content": f"Classify the following query into 'Chemotherapy' or 'Traffic Law': {query}"}],
 
 
 
21
  max_tokens=60
22
  )
23
- return response['choices'][0]['message']['content'].strip()
 
 
 
 
24
  except Exception as e:
25
  print(f"Error during classification: {e}")
26
  return None
 
15
  def classify_query(query):
16
  llm = get_llm()
17
  try:
18
+ response = openai.chat.completions.create(
19
  model="gpt-3.5-turbo-16k",
20
+ messages=[
21
+ {"role": "system", "content": "Respond with classifying the query into 'Chemotherapy' or 'Traffic Law' based on the content of the user's query. Do not respond with anything else. Only 'Chemotherapy' or 'Traffic Law' depending on whichever field the query is closest to."},
22
+ {"role": "user", "content": f"{query}"}
23
+ ],
24
  max_tokens=60
25
  )
26
+ category = response.choices[0].message.content
27
+ if category in ["Chemotherapy", "Traffic Law"]:
28
+ return category
29
+ else:
30
+ return None
31
  except Exception as e:
32
  print(f"Error during classification: {e}")
33
  return None