messages = [ ( "system", "You are a helpful assistant that translates English to French. Translate the user sentence.", ), ("human", "I love programming."),]ai_msg = llm.invoke(messages)ai_msg
from typing import Listfrom langchain.messages import AIMessagefrom langchain.tools import toolfrom langchain_ollama import ChatOllama@tooldef validate_user(user_id: int, addresses: List[str]) -> bool: """Validate user using historical addresses. Args: user_id (int): the user ID. addresses (List[str]): Previous addresses as a list of strings. """ return Truellm = ChatOllama( model="gpt-oss:20b", validate_model_on_init=True, temperature=0,).bind_tools([validate_user])result = llm.invoke( "Could you validate user 123? They previously lived at " "123 Fake St in Boston MA and 234 Pretend Boulevard in " "Houston TX.")if isinstance(result, AIMessage) and result.tool_calls: print(result.tool_calls)
from langchain_ollama import ChatOllamallm = ChatOllama(model="llama3.1", logprobs=True)response = llm.invoke("What color is the sky?")logprobs = response.response_metadata["logprobs"]for entry in logprobs[:5]: print(f"Token: {entry['token']!r:>15} logprob: {entry['logprob']:.4f}")
llm = ChatOllama(model="llama3.1", logprobs=True, top_logprobs=3)response = llm.invoke("The capital of France is")logprobs = response.response_metadata["logprobs"]for entry in logprobs[:3]: print(f"Chosen: {entry['token']!r}") if entry.get("top_logprobs"): for alt in entry["top_logprobs"]: print(f" {alt['token']!r:>12} logprob: {alt['logprob']:.4f}")
Here is my thought process:The user is asking for the value of 3 raised to the power of 3, which is a basic exponentiation operation.Here is my response:3^3 (read as "3 to the power of 3") equals 27.This calculation is performed by multiplying 3 by itself three times: 3*3*3 = 27.