Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
Created June 20, 2025 08:25
Show Gist options
  • Save stevedoyle/3cba74fc871a81e6707a0ab5945e023f to your computer and use it in GitHub Desktop.
Save stevedoyle/3cba74fc871a81e6707a0ab5945e023f to your computer and use it in GitHub Desktop.
A simple example of how to send prompts to an LLM using LiteLLM
# A simple example of how to send prompts to an LLM using LiteLLM:
#
# Set your API key as shown in the Google Colab
#
import os
from google.colab import userdata
api_key = userdata.get('OPENAI_API_KEY')
os.environ['OPENAI_API_KEY'] = api_key
from litellm import completion
from typing import List, Dict
def generate_response(messages: List[Dict]) -> str:
"""Call LLM to get response"""
response = completion(
model="openai/gpt-4o",
messages=messages,
max_tokens=1024
)
return response.choices[0].message.content
messages = [
{"role": "system", "content": "You are an expert software engineer that prefers functional programming."},
{"role": "user", "content": "Write a function to swap the keys and values in a dictionary."}
]
response = generate_response(messages)
print(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment