Source code for app.utils.llm_api

import time

[docs] def gemini_api(prompt: str, model) -> str: """ Get answer via API of gemini. NOTICE: time.sleep(5) is to avoid reach rate limit per minutes, this can be deleted if there's a pro account. :param prompt: the given prompt to LLM-gemini. :return: the answer from LLM. """ response = model.generate_content(prompt) result = response.text.strip() # Request per minute is 15, sleep for 5 seconds can avoid crash. time.sleep(5) return result
[docs] def together_api(prompt: str) -> str: from together import Together API_KEY = "" client = Together(API_KEY) response = client.chat.completions.create( model="meta-llama/Meta-Llama-3-8B-Instruct-Turbo", messages=[{"role": "user", "content": prompt}], ) return response.choices[0].message.content
if __name__ == "__main__": prompt = "whats the capital of france?" print (together_api(prompt))