Use OpenAI’s gpt-oss-120b on Cerebras’ ultra-fast inference with and Linkup function calling for real-time web search integration
This guide will help you leverage Cerebras’ lightning-fast (3,000+ tokens/sec) inference with OpenAI’s gpt-oss-120b model combined with real-time web data to create powerful and responsive applications.
Create a simple function to search the web with LinkUp:
Copy
Ask AI
def search_web(query: str): linkup_client = LinkupClient(api_key=LINKUP_API_KEY) response = linkup_client.search(query=query, depth="standard", output_type="searchResults") # Format the results results = [] for i, doc in enumerate(response.results, 1): results.append(f"{i}. {doc.content}") return "\n".join(results)
4
Define the Search Tool
Tell Cerebras about the search function it can use:
Copy
Ask AI
tools = [ { "type": "function", "function": { "name": "search_web", "description": "Search the web in real time. Use this tool whenever the user needs trusted facts, news, source-backed information, or anything to which you don't have the answer. Returns comprehensive content from the most relevant sources.", "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "What to search for" } }, "required": ["query"] } } }]
5
Use It
Now you can chat with web search capabilities:
Copy
Ask AI
# Create your conversationmessages = [ {"role": "system", "content": "You are a helpful assistant. Use web search when you need current information."}, {"role": "user", "content": "What are the latest AI developments this week?"}]# Get response from Cerebrasresponse = client.chat.completions.create( model="gpt-oss-120b", messages=messages, tools=tools)# Check if the model wants to searchif response.choices[0].message.tool_calls: # The model decided to search tool_call = response.choices[0].message.tool_calls[0] search_query = json.loads(tool_call.function.arguments)["query"] print(f"Searching for: {search_query}") search_results = search_web(search_query) # Add the search results to the conversation messages.append(response.choices[0].message) messages.append({ "role": "tool", "tool_call_id": tool_call.id, "content": search_results }) # Get final response with search results final_response = client.chat.completions.create( model="gpt-oss-120b", messages=messages ) print(final_response.choices[0].message.content)else: # No search needed print(response.choices[0].message.content)
6
Try Different Questions
Test with different types of questions:
Copy
Ask AI
# Try other questions by changing the user message:# For current events:# {"role": "user", "content": "What's happening with Tesla stock today?"}# For general knowledge (no search needed):# {"role": "user", "content": "What is Python programming?"}# For recent news:# {"role": "user", "content": "What are today's top tech headlines?"}