Skip to content

Instantly share code, notes, and snippets.

@rajivmehtaflex
Last active January 14, 2025 03:45
Show Gist options
  • Save rajivmehtaflex/cf56f69e10ddb80fd97a4239055a8567 to your computer and use it in GitHub Desktop.
Save rajivmehtaflex/cf56f69e10ddb80fd97a4239055a8567 to your computer and use it in GitHub Desktop.
UV-Python-Manager
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gemini-1.5-flash-002",
api_key='<KEY>',
base_url="https://generativelanguage.googleapis.com/v1beta/",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
)
if __name__ == "__main__":
while True:
user_input = input("You: ")
if user_input.lower() == 'exit':
break
response = llm.invoke([
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": user_input}
])
print("Assistant:", response.content)
---------------------------
Run OpenAI Swarm Framework
Setup following environment variables[for Ollama,rest are the same]
export OPENAI_MODEL_NAME=llama-3.2
export OPENAI_BASE_URL=http://localhost:11434/v1
export OPENAI_API_KEY=your_api_key_here
Rest of the thing are same as per swarm documentations

/// script

requires-python = ">=3.8"

dependencies = ["requests==2.28.1"]

///

import requests import sys

def get_website_status(url): """Fetches the status code of a website.""" try: response = requests.get(url) response.raise_for_status() # Raise an exception for bad status codes return response.status_code except requests.exceptions.RequestException as e: print(f"Error fetching URL: {e}") return None

if name == "main": url = "https://www.google.com" # Example website status_code = get_website_status(url)

if status_code:
    print(f"Status code for {url}: {status_code}")
    print(f"Status for python version {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment