Skip to content

Commit

Permalink
open ai api integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ariefrahmansyah committed Aug 28, 2024
1 parent d1d8e01 commit c0d847d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/gen_ai/intro_to_llm.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Learn more about LLM concepts here:
1. [Transformer Explainer](https://poloclub.github.io/transformer-explainer/)
1. [What Is ChatGPT Doing … and Why Does It Work?](https://writings.stephenwolfram.com/2023/02/what-is-chatgpt-doing-and-why-does-it-work/)
1. [Jay Alammar's blog](https://jalammar.github.io/)
1. [The Illustrated Word2vec](https://jalammar.github.io/illustrated-word2vec/)
1. [Visualizing A Neural Machine Translation Model (Mechanics of Seq2seq Models With Attention)](https://jalammar.github.io/visualizing-neural-machine-translation-mechanics-of-seq2seq-models-with-attention/)
1. [The Illustrated Transformer](https://jalammar.github.io/illustrated-transformer/)
1. [The Illustrated GPT-2 (Visualizing Transformer Language Models)](https://jalammar.github.io/illustrated-gpt2/)
Expand Down
Binary file added docs/images/openai_api_integration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 63 additions & 1 deletion docs/tutorials/openai_api.md
Original file line number Diff line number Diff line change
@@ -1 +1,63 @@
# 🚧 Integration with OpenAI API
# Integration with OpenAI API

![OpenAI API Integration Options](../images/openai_api_integration.png)

## Local to Online LLM

Prerequisites:

```
pip install openai phidata duckduckgo-search
```

### OpenAI API

Pertama-tama, kamu harus membuat OpenAI API key terlebih dahulu. Kamu bisa mengikuti caranya di sini: https://openrouter.ai/docs/api-keys

Setelah itu, set environment variable OPENAI_API_KEY dengan API key yang kamu dapatkan.

```bash
export OPENAI_API_KEY=***
```

Setelah itu, kamu bisa menggunakan OpenRouter API dengan cara berikut:

```python
from phi.assistant import Assistant
from phi.llm.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGo

assistant = Assistant(
llm=OpenAIChat(model="gpt-4o", max_tokens=500, temperature=0.3),
tools=[DuckDuckGo()],
show_tool_calls=True,
)
assistant.print_response("Whats happening in France?", markdown=True)
```

### OpenRouter.ai

Pertama-tama, kamu harus membuat OpenRouter API key terlebih dahulu. Kamu bisa mengikuti caranya di sini: https://openrouter.ai/docs/api-keys

Setelah itu, set environment variable OPENROUTER_API_KEY dengan API key yang kamu dapatkan.

```bash
export OPENROUTER_API_KEY=***
```

Setelah itu, kamu bisa menggunakan OpenRouter API dengan cara berikut:

```python
from phi.assistant import Assistant
from phi.llm.openrouter import OpenRouter

assistant = Assistant(
llm=OpenRouter(model="mistralai/mistral-7b-instruct:free"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True)
```

## Local LLMs

Kamu bisa mengikut guide di sini: [Local LLMs](../gen_ai/local_llms)

0 comments on commit c0d847d

Please sign in to comment.