Skip to content

Commit

Permalink
update-contribution-guide-phi-1764
Browse files Browse the repository at this point in the history
  • Loading branch information
ysolanky committed Oct 24, 2024
1 parent 7b4c0fa commit e70607f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
44 changes: 25 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ Please follow the [fork and pull request](https://docs.github.com/en/get-started
## Formatting and validation

Ensure your code meets our quality standards by running the appropriate formatting and validation script before submitting a pull request:
- For Unix: `./scripts/format.sh`
- For Windows: `.\scripts\format.bat`
These scripts will perform code formatting with `ruff`, static type checks with `mypy`, and run unit tests with `pytest`.
- For Unix:
- `./scripts/format.sh`
- `./scripts/validate.sh`
- For Windows:
- `.\scripts\format.bat`
- `.\scripts\validate.bat`

These scripts will perform code formatting with `ruff`, static type checks with `mypy`, and run unit tests with `pytest`.

## Adding a new Vector Database

Expand All @@ -42,34 +46,36 @@ These scripts will perform code formatting with `ruff`, static type checks with
- Your Class will be in the `phi/vectordb/<your_db>/<your_db>.py` file.
- The `VectorDb` interface is defined in `phi/vectordb/base
- Import your `VectorDb` Class in `phi/vectordb/<your_db>/__init__.py`.
- Checkout the [`phi/vectordb/pgvector/pgvector2`](https://github.com/phidatahq/phidata/blob/main/phi/vectordb/pgvector/pgvector2.py) file for an example.
4. Add a recipe for using your `VectorDb` under `cookbook/<your_db>`.
- Checkout [`phidata/cookbook/pgvector`](https://github.com/phidatahq/phidata/tree/main/cookbook/pgvector) for an example (you do not need to add the `resources.py` file).
5. Important: Format and validate your code by running `./scripts/format.sh`.
- Checkout the [`phi/vectordb/pgvector/pgvector`](https://github.com/phidatahq/phidata/blob/main/phi/vectordb/pgvector/pgvector.py) file for an example.
4. Add a recipe for using your `VectorDb` under `cookbook/vectordb/<your_db>`.
- Checkout [`phidata/cookbook/vectordb/pgvector`](https://github.com/phidatahq/phidata/tree/main/cookbook/vectordb/pgvector) for an example.
5. Important: Format and validate your code by running `./scripts/format.sh` and `./scripts/validate.sh`.
6. Submit a pull request.

## Adding a new LLM provider
## Adding a new Model Provider

1. Setup your local environment by following the [Development setup](#development-setup).
2. Create a new directory under `phi/llm` for the new LLM provider.
3. If the LLM provider supports the OpenAI API spec:
- Create a Class for your LLM provider that inherits the `OpenAILike` Class from `phi/llm/openai/like.py`.
- Your Class will be in the `phi/llm/<your_llm>/<your_llm>.py` file.
- Import your Class in the `phi/llm/<your_llm>/__init__.py` file.
- Checkout the [`phi/llm/together/together.py`](https://github.com/phidatahq/phidata/blob/main/phi/llm/together/together.py) file for an example.
4. If the LLM provider does not support the OpenAI API spec:
2. Create a new directory under `phi/model` for the new Model provider.
3. If the Model provider supports the OpenAI API spec:
- Create a Class for your LLM provider that inherits the `OpenAILike` Class from `phi/model/openai/like.py`.
- Your Class will be in the `phi/model/<your_model>/<your_model>.py` file.
- Import your Class in the `phi/model/<your_model>/__init__.py` file.
- Checkout the [`phi/model/xai/xai.py`](https://github.com/phidatahq/phidata/blob/main/phi/llm/together/together.py) file for an example.
4. If the Model provider does not support the OpenAI API spec:
- Reach out to us on [Discord](https://discord.gg/4MtYHHrgA8) or open an issue to discuss the best way to integrate your LLM provider.
5. Add a recipe for using your LLM provider under `cookbook/<your_llm>`.
- Checkout [`phidata/cookbook/together`](https://github.com/phidatahq/phidata/tree/main/cookbook/together) for an example.
6. Important: Format and validate your code by running `./scripts/format.sh`.
- Checkout [`phi/model/anthropic/claude.py`](https://github.com/phidatahq/phidata/blob/main/phi/model/anthropic/claude.py) or [`phi/model/cohere/chat.py`](https://github.com/phidatahq/phidata/blob/main/phi/model/cohere/chat.py) for inspiration.
5. Add a recipe for using your Model provider under `cookbook/providers/<your_model>`.
- Checkout [`phidata/cookbook/provider/claude`](https://github.com/phidatahq/phidata/tree/main/cookbook/providers/claude) for an example.
6. Important: Format and validate your code by running `./scripts/format.sh` and `./scripts/validate.sh`.
7. Submit a pull request.

Message us on [Discord](https://discord.gg/4MtYHHrgA8) if you have any questions or need help with credits.
Message us on [Discord](https://discord.gg/4MtYHHrgA8) or post on [Discourse](https://community.phidata.com/) if you have any questions or need help with credits.

## 📚 Resources

- <a href="https://docs.phidata.com/introduction" target="_blank" rel="noopener noreferrer">Documentation</a>
- <a href="https://discord.gg/4MtYHHrgA8" target="_blank" rel="noopener noreferrer">Discord</a>
- <a href="https://community.phidata.com/" target="_blank" rel="noopener noreferrer">Discourse</a>

## 📝 License

Expand Down
Empty file added cookbook/vectordb/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions cookbook/vectordb/pgvector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from phi.agent import Agent
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

knowledge_base = PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector(table_name="recipes", db_url=db_url),
)
knowledge_base.load(recreate=False) # Comment out after first run

agent = Agent(knowledge_base=knowledge_base, use_tools=True, show_tool_calls=True)
agent.print_response("How to make Thai curry?", markdown=True)

0 comments on commit e70607f

Please sign in to comment.