Linkup raises $10M seed to build web search for AI. Read more →
Use Mistral AI’s function calling capabilities to integrate with Linkup
Get your API Keys
Install and Setup
pip install linkup-sdk mistralai
from mistralai import Mistral from linkup import LinkupClient import json from datetime import datetime mistral_client = Mistral(api_key="your_mistral_api_key") linkup_client = LinkupClient(api_key="your_linkup_api_key")
Define the Function Schema
tools = [{ "type": "function", "function": { "name": "search_web", "description": "Search the web for current information. Returns comprehensive content from relevant sources.", "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "The search query" } }, "required": ["query"] } } }]
Build the Chatbot
system_prompt = f"You are a helpful assistant. Today is {datetime.now().strftime('%B %d, %Y')}. Use web search when you need current information." messages = [{"role": "system", "content": system_prompt}] print("Chatbot ready! Type 'quit' to exit.\n") while True: user_input = input("You: ").strip() if not user_input or user_input.lower() == "quit": break messages.append({"role": "user", "content": user_input}) try: response = mistral_client.chat.complete( model="mistral-large-latest", messages=messages, tools=tools ) message = response.choices[0].message while message.tool_calls: messages.append(message) for tool_call in message.tool_calls: args = json.loads(tool_call.function.arguments) print(f"Searching with Linkup: {args['query']}...") linkup_response = linkup_client.search( query=args["query"], depth="standard", output_type="searchResults" ) search_results = json.dumps( [{"content": r.content} for r in linkup_response.results] ) messages.append({ "role": "tool", "name": "search_web", "content": search_results, "tool_call_id": tool_call.id }) response = mistral_client.chat.complete( model="mistral-large-latest", messages=messages, tools=tools ) message = response.choices[0].message print(f"\nAssistant: {message.content}\n") messages.append({"role": "assistant", "content": message.content}) except Exception as e: print(f"Error: {e}\n") messages.pop()