chore: import upstream snapshot with attribution
Ruff / Ruff (push) Has been cancelled
Test / Core Tests (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.10) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.11) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.12) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.13) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.9) (push) Has been cancelled
Test / Full Coverage (Python 3.11) (push) Has been cancelled
Test / Core Provider Tests (OpenAI) (push) Has been cancelled
Test / Core Provider Tests (Anthropic) (push) Has been cancelled
Test / Core Provider Tests (Google) (push) Has been cancelled
Test / Core Provider Tests (Other) (push) Has been cancelled
Test / Anthropic Tests (push) Has been cancelled
Test / Gemini Tests (push) Has been cancelled
Test / Google GenAI Tests (push) Has been cancelled
Test / Vertex AI Tests (push) Has been cancelled
Test / OpenAI Tests (push) Has been cancelled
Test / Writer Tests (push) Has been cancelled
Test / Auto Client Tests (push) Has been cancelled
ty / type-check (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:36:38 +08:00
commit 97e91a83f3
978 changed files with 159975 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
# Read first to correctly work with the provided examples
## Open Router
1. Sign up for an Openrouter Account - https://accounts.openrouter.ai/sign-up
2. Create an API key - https://openrouter.ai/keys
3. Add API key to environment - `export OPENROUTER_API_KEY=your key here`
4. Add Openrouter API endpoint to environment - `export OPENROUTER_BASE_URL=https://openrouter.ai/api/v1` [See https://openrouter.ai/docs#format for potential updates]
## Perplexity
1. Sign up for an Openrouter Account - https://www.perplexity.ai/
2. Create an API key - https://www.perplexity.ai/pplx-api
3. Add API key to environment - `export PERPLEXITY_API_KEY=your key here`
4. Add Openrouter API endpoint to environment - `export PERPLEXITY_BASE_URL=https://api.perplexity.ai` [See https://docs.perplexity.ai/reference/post_chat_completions for potential updates]
## Runpod
1. Sign up for a Runpod account - https://www.runpod.io/console/signup
2. Add credits, unfortunately no free tier. - https://www.runpod.io/console/user/billing
3. Navigate to templates page[Left selection menu], under `Official` click deploy on `RunPod TheBloke LLMs` template. - https://www.runpod.io/console/templates
4. Navigate to Community Cloud page [Left Selection menu], Click `Deploy` on a GPU with >=16 GB, 1x RTX 4000 Ada SFF works. - https://www.runpod.io/console/gpu-cloud
5. Click `Customize Deployment`, click the `Environment Variables` drop down, Enter the following Key/Values, then click `Set Overrides`, then click `Continue`, and finally `Deploy`.
- key=MODEL value=TheBloke/OpenHermes-2.5-Mistral-7B-GPTQ
- key=UI_ARGS value=--n-gpu-layers 100 --threads 1
6. Navigate to Pods[Left selection menu], wait until you see `Connect` button on the Pod you just deployed, click it. Right click `HTTP Service[Port 5000]` and copy the link address. - https://www.runpod.io/console/pods
- Add Runpod API endpoint to environment - `export RUNPOD_BASE_URL=your-runpod-link/v1` <-- Make sure to add v1 as well
- Add Runpod API key to environment - `export RUNPOD_API_KEY="None"` <-- This should be none.
7. When done running, stop instance by clicking the stop icon on the Pod page. - https://www.runpod.io/console/pods
@@ -0,0 +1,62 @@
import os
import instructor
from openai import OpenAI
from pydantic import BaseModel, Field
from typing import Optional
from instructor import Maybe, Mode
# Extract API key from environment
openrouter_api_key = os.environ.get("OPENROUTER_API_KEY")
assert openrouter_api_key, "OPENROUTER_API_KEY is not set in environment variables"
# Base URL for OpenAI client
openrouter_base_url = os.environ.get("OPENROUTER_BASE_URL")
assert openrouter_base_url, "OPENROUTER_BASE_URL is not set in environment variables"
# Initialize OpenAI client
client = instructor.from_openai(
OpenAI(api_key=openrouter_api_key, base_url=openrouter_base_url),
mode=Mode.JSON,
)
data = [
"Brandon is 33 years old. He works as a solution architect.",
"Jason is 25 years old. He is the GOAT.",
"Dominic is 45 years old. He is retired.",
"Jenny is 72. She is a wife and a CEO.",
"Holly is 22. She is an explorer.",
"There onces was a prince, named Benny. He ruled for 10 years, which just ended. He started at 22.",
"Simon says, why are you 22 years old marvin?",
]
if __name__ == "__main__":
class UserDetail(BaseModel):
name: str = Field(description="Name extracted from the text")
age: int = Field(description="Age extracted from the text")
occupation: Optional[str] = Field(
default=None, description="Occupation extracted from the text"
)
for content in data:
MaybeUser = Maybe(UserDetail)
user = client.chat.completions.create(
response_model=MaybeUser,
model="teknium/openhermes-2.5-mistral-7b",
messages=[
{
"role": "system",
"content": f"You are an expert at outputting json. You always output valid json based on this schema: {MaybeUser.model_json_schema()}",
},
{
"role": "user",
"content": f"Extract the user details from the following text: {content}. Match your response the correct schema",
},
],
)
# Output the error or the result.
if user.error:
print(f"Error: {user.error}")
if user.result:
print(f"Result: {user.result}")
@@ -0,0 +1,75 @@
import os
import instructor
from openai import OpenAI
from pydantic import BaseModel, Field
from typing import Optional
from instructor import Maybe, Mode
# Extract API key from environment
perplexity_api_key = os.environ.get("PERPLEXITY_API_KEY")
assert perplexity_api_key, "PERPLEXITY_API_KEY is not set in environment variables"
# Base URL for OpenAI
perplexity_base_url = os.environ.get("PERPLEXITY_BASE_URL")
assert perplexity_base_url, "PERPLEXITY_BASE_URL is not set in environment variables"
# Initialize OpenAI client
client = instructor.from_openai(
OpenAI(api_key=perplexity_api_key, base_url=perplexity_base_url),
mode=Mode.JSON,
)
# For direct reference here. See https://docs.perplexity.ai/docs/model-cards for updates
# Recommended is pplx-70b-chat
models = [
"codellama-34b-instruct",
"llama-2-70b-chat",
"mistral-7b-instruct",
"pplx-7b-chat",
"pplx-70b-chat",
"pplx-7b-online",
"pplx-70b-online",
]
data = [
"Brandon is 33 years old. He works as a solution architect.",
"Jason is 25 years old. He is the GOAT.",
"Dominic is 45 years old. He is retired.",
"Jenny is 72. She is a wife and a CEO.",
"Holly is 22. She is an explorer.",
"There onces was a prince, named Benny. He ruled for 10 years, which just ended. He started at 22.",
"Simon says, why are you 22 years old marvin?",
]
if __name__ == "__main__":
class UserDetail(BaseModel):
name: str = Field(description="Name extracted from the text")
age: int = Field(description="Age extracted from the text")
occupation: Optional[str] = Field(
default=None, description="Occupation extracted from the text"
)
for content in data:
MaybeUser = Maybe(UserDetail)
user = client.chat.completions.create(
response_model=MaybeUser,
model="pplx-70b-chat",
messages=[
{
"role": "system",
"content": "You are an expert at outputting json. You always output valid JSON based on the pydantic schema given to you.",
},
{
"role": "user",
"content": f"Extract the user details from the following text: {content}. Match your response to the following schema: {MaybeUser.model_json_schema()}",
},
],
max_retries=3,
)
# Output the error or the result.
if user.error:
print(f"Error: {user.error}")
if user.result:
print(f"Result: {user.result}")
+62
View File
@@ -0,0 +1,62 @@
import os
import instructor
from openai import OpenAI
from pydantic import BaseModel, Field
from typing import Optional
from instructor import Mode
# Extract API key from environment
runpod_api_key = os.environ.get("RUNPOD_API_KEY")
assert runpod_api_key, "RUNPOD_API_KEY is not set in environment variables"
# Base URL for OpenAI client
runpod_base_url = os.environ.get("RUNPOD_BASE_URL")
assert runpod_base_url, "RUNPOD_BASE_URL is not set in environment variables"
# Initialize OpenAI client
client = instructor.from_openai(
OpenAI(api_key=runpod_api_key, base_url=runpod_base_url),
mode=Mode.JSON,
)
data = [
"Brandon is 33 years old. He works as a solution architect.",
"Jason is 25 years old. He is the GOAT.",
"Dominic is 45 years old. He is retired.",
"Jenny is 72. She is a wife and a CEO.",
"Holly is 22. She is an explorer.",
"There onces was a prince, named Benny. He ruled for 10 years, which just ended. He started at 22.",
"Simon says, why are you 22 years old marvin?",
]
if __name__ == "__main__":
class UserDetail(BaseModel):
name: str = Field(description="Name extracted from the text")
age: int = Field(description="Age extracted from the text")
occupation: Optional[str] = Field(
default=None, description="Occupation extracted from the text"
)
for content in data:
try:
user = client.chat.completions.create(
response_model=UserDetail,
model="TheBloke_OpenHermes-2.5-Mistral-7B-GPTQ",
messages=[
{
"role": "system",
"content": "You are an expert at outputting json. You output valid JSON.",
},
{
"role": "user",
"content": f"Extract the user details from the following text: {content}. Match your response to the following schema: {UserDetail.model_json_schema()}",
},
],
)
print(f"Result: {user}")
except Exception as e:
print(f"Error: {e}")
continue