pvanand commited on
Commit
676b3da
·
verified ·
1 Parent(s): b128493

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -8
main.py CHANGED
@@ -46,9 +46,10 @@ def json_from_text(text):
46
  fix_json = JSONFixer()
47
  return loads(fix_json.fix(json_out).line)
48
 
49
- def generate_topics(user_input,num_topics,previous_query):
50
- prompt = f"""create a list of {num_topics} subtopics to follow for conducting {user_input} in the context of {previous_query}, RETURN VALID PYTHON LIST"""
51
- response_topics = together_response(prompt, model = "meta-llama/Llama-3-8b-chat-hf", SysPrompt = SysPromptList)
 
52
  subtopics = json_from_text(response_topics)
53
  return subtopics
54
 
@@ -67,15 +68,14 @@ app.add_middleware(
67
  class TopicInput(BaseModel):
68
  user_input: str = Query(default="market research", description="input query to generate subtopics")
69
  num_topics: int = Query(default=5, description="Number of subtopics to generate (default: 5)")
70
- previous_query: str = Query(default="", description="Previous query for context (default: empty string)")
71
 
72
- @app.get("/",tags=["Home"])
73
  def api_home():
74
- return {'detail': 'Welcome to FastAPI Subtopics API! /n visit https://pvanand-generate-subtopics.hf.space/docs to test'}
75
-
76
 
77
  @app.post("/generate_topics")
78
  async def create_topics(input: TopicInput):
79
- topics = generate_topics(input.user_input, input.num_topics, input.previous_query)
80
  return {"topics": topics}
81
 
 
46
  fix_json = JSONFixer()
47
  return loads(fix_json.fix(json_out).line)
48
 
49
+ def generate_topics(user_input, num_topics, previous_queries):
50
+ previous_context = " -> ".join(previous_queries)
51
+ prompt = f"""create a list of {num_topics} subtopics to follow for conducting {user_input} in the context of {previous_context}, RETURN VALID PYTHON LIST"""
52
+ response_topics = together_response(prompt, model="meta-llama/Llama-3-8b-chat-hf", SysPrompt=None)
53
  subtopics = json_from_text(response_topics)
54
  return subtopics
55
 
 
68
  class TopicInput(BaseModel):
69
  user_input: str = Query(default="market research", description="input query to generate subtopics")
70
  num_topics: int = Query(default=5, description="Number of subtopics to generate (default: 5)")
71
+ previous_queries: list[str] = Query(default=[], description="List of previous queries for context")
72
 
73
+ @app.get("/", tags=["Home"])
74
  def api_home():
75
+ return {'detail': 'Welcome to FastAPI Subtopics API! Visit https://pvanand-generate-subtopics.hf.space/docs to test'}
 
76
 
77
  @app.post("/generate_topics")
78
  async def create_topics(input: TopicInput):
79
+ topics = generate_topics(input.user_input, input.num_topics, input.previous_queries)
80
  return {"topics": topics}
81