Mirascope is a powerful, flexible, and user-friendly library that simplifies the process of working with LLMs through a unified interface that works across various supported providers, including OpenAI, Anthropic, Mistral, Gemini, Groq, Cohere, LiteLLM, Azure AI, Vertex AI, and Bedrock.
Whether you're generating text, extracting structured information, or developing complex AI-driven agent systems, Mirascope provides the tools you need to streamline your development process and create powerful, robust applications.
Make your first call to an LLM to recommend a book for a given genre:
Mirascope
frommirascope.coreimportopenai@openai.call("gpt-4o-mini")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportanthropic@anthropic.call("claude-3-5-sonnet-20240620")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportmistral@mistral.call("mistral-large-latest")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportgemini@gemini.call("gemini-1.5-flash")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportgroq@groq.call("llama-3.1-70b-versatile")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportcohere@cohere.call("command-r-plus")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportlitellm@litellm.call("gpt-4o-mini")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportazure@azure.call("gpt-4o-mini")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportvertex@vertex.call("gemini-1.5-flash")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportbedrock@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")defrecommend_book(genre:str)->str:returnf"Recommend a {genre} book"response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,openai@openai.call("gpt-4o-mini")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,anthropic@anthropic.call("claude-3-5-sonnet-20240620")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,mistral@mistral.call("mistral-large-latest")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,gemini@gemini.call("gemini-1.5-flash")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,groq@groq.call("llama-3.1-70b-versatile")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,cohere@cohere.call("command-r-plus")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,litellm@litellm.call("gpt-4o-mini")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,azure@azure.call("gpt-4o-mini")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,vertex@vertex.call("gemini-1.5-flash")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportMessages,bedrock@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")defrecommend_book(genre:str)->Messages.Type:returnMessages.User(f"Recommend a {genre} book")response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportopenai,prompt_template@openai.call("gpt-4o-mini")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportanthropic,prompt_template@anthropic.call("claude-3-5-sonnet-20240620")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportmistral,prompt_template@mistral.call("mistral-large-latest")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportgemini,prompt_template@gemini.call("gemini-1.5-flash")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportgroq,prompt_template@groq.call("llama-3.1-70b-versatile")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportcohere,prompt_template@cohere.call("command-r-plus")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportlitellm,prompt_template@litellm.call("gpt-4o-mini")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportazure,prompt_template@azure.call("gpt-4o-mini")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportprompt_template,vertex@vertex.call("gemini-1.5-flash")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportbedrock,prompt_template@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")@prompt_template("Recommend a {genre} book")defrecommend_book(genre:str):...response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,openai@openai.call("gpt-4o-mini")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,anthropic@anthropic.call("claude-3-5-sonnet-20240620")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,mistral@mistral.call("mistral-large-latest")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,gemini@gemini.call("gemini-1.5-flash")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,groq@groq.call("llama-3.1-70b-versatile")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,cohere@cohere.call("command-r-plus")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,litellm@litellm.call("gpt-4o-mini")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,azure@azure.call("gpt-4o-mini")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,vertex@vertex.call("gemini-1.5-flash")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
frommirascope.coreimportBaseMessageParam,bedrock@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")defrecommend_book(genre:str)->list[BaseMessageParam]:return[BaseMessageParam(role="user",content=f"Recommend a {genre} book")]response=recommend_book("fantasy")print(response.content)
Official SDK
fromopenaiimportOpenAIclient=OpenAI()defrecommend_book(genre:str)->str:completion=client.chat.completions.create(model="gpt-4o-mini",messages=[{"role":"user","content":f"Recommend a {genre} book"}],)returnstr(completion.choices[0].message.content)output=recommend_book("fantasy")print(output)
fromanthropicimportAnthropicclient=Anthropic()defrecommend_book(genre:str)->str:message=client.messages.create(model="claude-3-5-sonnet-20240620",messages=[{"role":"user","content":f"Recommend a {genre} book"}],max_tokens=1024,)block=message.content[0]returnblock.textifblock.type=="text"else""output=recommend_book("fantasy")print(output)
frommistralai.clientimportMistralClientclient=MistralClient()defrecommend_book(genre:str)->str:completion=client.chat(model="mistral-large-latest",messages=[{"role":"user","content":f"Recommend a {genre} book"}],)returncompletion.choices[0].message.contentoutput=recommend_book("fantasy")print(output)
fromgoogle.generativeaiimportGenerativeModelclient=GenerativeModel("gemini-1.5-flash")defrecommend_book(genre:str)->str:generation=client.generate_content(contents=[{"role":"user","parts":f"Recommend a {genre} book"}]# pyright: ignore [reportArgumentType])returngeneration.candidates[0].content.parts[0].textoutput=recommend_book("fantasy")print(output)
fromgroqimportGroqclient=Groq()defrecommend_book(genre:str)->str:completion=client.chat.completions.create(model="llama-3.1-70b-versatile",messages=[{"role":"user","content":f"Recommend a {genre} book"}],)returnstr(completion.choices[0].message.content)output=recommend_book("fantasy")print(output)
fromcohereimportClientclient=Client()defrecommend_book(genre:str)->str:response=client.chat(model="command-r-plus",message=f"Recommend a {genre} book",)returnresponse.textoutput=recommend_book("fantasy")print(output)
fromlitellmimportcompletiondefrecommend_book(genre:str)->str:response=completion(model="gpt-4o-mini",messages=[{"role":"user","content":f"Recommend a {genre} book"}],)returnstr(response.choices[0].message.content)# type: ignoreoutput=recommend_book("fantasy")print(output)
fromazure.ai.inferenceimportChatCompletionsClientfromazure.ai.inference.modelsimportChatRequestMessagefromazure.core.credentialsimportAzureKeyCredentialclient=ChatCompletionsClient(endpoint="YOUR_ENDPOINT",credential=AzureKeyCredential("YOUR_KEY"))defrecommend_book(genre:str)->str:completion=client.complete(model="gpt-4o-mini",messages=[ChatRequestMessage({"role":"user","content":f"Recommend a {genre} book"})],)message=completion.choices[0].messagereturnmessage.contentifmessage.contentisnotNoneelse""output=recommend_book("fantasy")print(output)
fromvertexai.generative_modelsimportGenerativeModelclient=GenerativeModel("gemini-1.5-flash")defrecommend_book(genre:str)->str:generation=client.generate_content(contents=[{"role":"user","parts":f"Recommend a {genre} book"}])returngeneration.candidates[0].content.parts[0].text# type: ignoreoutput=recommend_book("fantasy")print(output)
importboto3bedrock_client=boto3.client(service_name="bedrock-runtime")defrecommend_book(genre:str)->str:messages=[{"role":"user","content":[{"text":f"Recommend a {genre} book"}]}]response=bedrock_client.converse(modelId="anthropic.claude-3-haiku-20240307-v1:0",messages=messages,inferenceConfig={"maxTokens":1024},)output_message=response["output"]["message"]content=""forcontent_pieceinoutput_message["content"]:if"text"incontent_piece:content+=content_piece["text"]returncontentoutput=recommend_book("fantasy")print(output)