Skip to content

code update #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions 00a_openai_api/01_chat_completion_api/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,49 +80,58 @@ The OpenAI Chat Completion API has become an industry standard, and APIs from Go
```python
import openai

openai.api_key = "YOUR_GOOGLE_API_KEY"
openai.api_base = "https://generativelanguage.googleapis.com/v1beta"
client = openai.Client(
api_key="YOUR_GOOGLE_API_KEY", # Set your Google API key
base_url="https://generativelanguage.googleapis.com/v1beta" # Google Gemini API base
)

response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="gemini-1.5-flash",
messages=[{"role": "user", "content": "Explain AI in simple terms."}]
)

print(response.choices[0].message.content)

```

### Anthropic (Claude 3)

```python
import openai

openai.api_key = "YOUR_ANTHROPIC_API_KEY"
openai.api_base = "https://api.anthropic.com/v1"
client = openai.Client(
api_key="YOUR_ANTHROPIC_API_KEY", # Set your Anthropic API key
base_url="https://api.anthropic.com/v1" # Anthropic API base
)

response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="claude-3-haiku-20240307",
messages=[{"role": "user", "content": "Summarize the plot of Hamlet in a paragraph."}],
temperature=0.5,
max_tokens=200
)

print(response.choices[0].message.content)

```

### DeepSeek

```python
import openai

openai.api_key = "YOUR_DEEPSEEK_API_KEY"
openai.api_base = "https://api.deepseek.com"
client = openai.Client(
api_key="YOUR_DEEPSEEK_API_KEY", # Set your DeepSeek API key
base_url="https://api.deepseek.com" # DeepSeek API base
)

response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Describe Quantum Computing."}]
)

print(response.choices[0].message.content)

```

## Tips for Cross-Provider Compatibility
Expand Down