Update TextGen/router.py
Browse files38 unmodified lines39404142434445464748495051521 unmodified line54555657585960616263646566676869708 unmodified lines7980818283848538 unmodified lines"Herbalist":"./voices/female.mp3","Bard":"./voices/Bard_voice.mp3"}class Generate(BaseModel):text:strdef generate_text(messages: List[str]):print(messages)prompt=messages[-1]prompt = PromptTemplate(template=prompt, input_variables=['Prompt'])# Initialize the LLMllm = ChatGoogleGenerativeAI(model="gemini-pro",1 unmodified lineHarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,},)llmchain = LLMChain(prompt=prompt,llm=llm)llm_response = llmchain.run({"Prompt": prompt})return Generate(text=llm_response)app.add_middleware(CORSMiddleware,allow_origins=["*"],8 unmodified lines@app.post("/api/generate", summary="Generate text from prompt", tags=["Generate"], response_model=Generate)def inference(message: Message):return generate_text(messages=message.messages)#Dummy function for nowdef determine_vocie_from_npc(npc,genre):38 unmodified lines394041424344454647484950515253545556575859606162631 unmodified line6566676869707172738 unmodified lines8283848586878838 unmodified lines"Herbalist":"./voices/female.mp3","Bard":"./voices/Bard_voice.mp3"}main_npc_system_prompts={"Blacksmith":"You are a blacksmith in a video game","Herbalist":"You are an herbalist in a video game","Bard":"You are a bard in a video game"}class Generate(BaseModel):text:strdef generate_text(messages: List[str], npc:str):print(npc)system_prompt=main_npc_system_prompts[npc]print(system_prompt)new_messages=[{"role": "system", "content": system_prompt}]for index, message in enumerate(messages):if index%2==0:new_messages.append({"role": "user", "content": message})else:new_messages.append({"role": "assistant", "content": message})print(new_messages)# Initialize the LLMllm = ChatGoogleGenerativeAI(model="gemini-pro",1 unmodified lineHarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,},)llm_response = llm.invoke(new_messages)return Generate(text=llm_response)app.add_middleware(CORSMiddleware,allow_origins=["*"],8 unmodified lines@app.post("/api/generate", summary="Generate text from prompt", tags=["Generate"], response_model=Generate)def inference(message: Message):return generate_text(messages=message.messages, npc=message.npc)#Dummy function for nowdef determine_vocie_from_npc(npc,genre):
TextGen/router.py+18-15