-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from SylphAI-Inc/main
[Release] Notebooks merge
- Loading branch information
Showing
41 changed files
with
10,758 additions
and
9,854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Define variables for common directories and commands | ||
PYTHON = poetry run | ||
SRC_DIR = . | ||
|
||
# Default target: Show help | ||
.PHONY: help | ||
help: | ||
@echo "Available targets:" | ||
@echo " setup Install dependencies and set up pre-commit hooks" | ||
@echo " format Run Black and Ruff to format the code" | ||
@echo " lint Run Ruff to check code quality" | ||
@echo " test Run tests with pytest" | ||
@echo " precommit Run pre-commit hooks on all files" | ||
@echo " clean Clean up temporary files and build artifacts" | ||
|
||
# Install dependencies and set up pre-commit hooks | ||
.PHONY: setup | ||
setup: | ||
poetry install | ||
poetry run pre-commit install | ||
|
||
# Format code using Black and Ruff | ||
.PHONY: format | ||
format: | ||
$(PYTHON) black $(SRC_DIR) | ||
git ls-files | xargs pre-commit run black --files | ||
|
||
# Run lint checks using Ruff | ||
.PHONY: lint | ||
lint: | ||
$(PYTHON) ruff check $(SRC_DIR) | ||
|
||
# Run all pre-commit hooks on all files | ||
.PHONY: precommit | ||
precommit: | ||
$(PYTHON) pre-commit run --all-files | ||
|
||
# Run tests | ||
.PHONY: test | ||
test: | ||
$(PYTHON) pytest | ||
|
||
# Clean up temporary files and build artifacts | ||
.PHONY: clean | ||
clean: | ||
rm -rf .pytest_cache | ||
rm -rf .mypy_cache | ||
rm -rf __pycache__ | ||
rm -rf build dist *.egg-info | ||
find . -type d -name "__pycache__" -exec rm -r {} + | ||
find . -type f -name "*.pyc" -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Dict | ||
import adalflow as adal | ||
from adalflow.components.model_client import GroqAPIClient | ||
|
||
# Define the QA template using jinja2 syntax | ||
qa_template = r"""<SYS> | ||
You are a helpful assistant. | ||
<OUTPUT_FORMAT> | ||
{{output_format_str}} | ||
</OUTPUT_FORMAT> | ||
</SYS> | ||
<USER> {{input_str}} </USER>""" | ||
|
||
|
||
# Define the output structure using dataclass | ||
@dataclass | ||
class BasicQAOutput(adal.DataClass): | ||
explanation: str = field( | ||
metadata={"desc": "A brief explanation of the concept in one sentence."} | ||
) | ||
example: str = field(metadata={"desc": "An example of the concept in a sentence."}) | ||
__output_fields__ = ["explanation", "example"] | ||
|
||
|
||
# Define the QA component | ||
class QA(adal.Component): | ||
def __init__(self, model_client: adal.ModelClient, model_kwargs: Dict): | ||
super().__init__() | ||
parser = adal.DataClassParser(data_class=BasicQAOutput, return_data_class=True) | ||
self.generator = adal.Generator( | ||
model_client=model_client, | ||
model_kwargs=model_kwargs, | ||
template=qa_template, | ||
prompt_kwargs={"output_format_str": parser.get_output_format_str()}, | ||
output_processors=parser, | ||
) | ||
|
||
def call(self, query: str): | ||
"""Synchronous call to generate response""" | ||
return self.generator.call({"input_str": query}) | ||
|
||
async def acall(self, query: str): | ||
"""Asynchronous call to generate response""" | ||
return await self.generator.acall({"input_str": query}) | ||
|
||
|
||
def run_basic_example(): | ||
"""Run a basic example of the QA component""" | ||
qa = QA( | ||
model_client=GroqAPIClient(), | ||
model_kwargs={"model": "llama3-8b-8192"}, | ||
) | ||
response = qa("What is LLM?") | ||
print("\nResponse:") | ||
print(response) | ||
print(f"BasicQAOutput: {response.data}") | ||
print(f"Explanation: {response.data.explanation}") | ||
print(f"Example: {response.data.example}") | ||
|
||
|
||
if __name__ == "__main__": | ||
print("Running basic QA example...") | ||
run_basic_example() |
Oops, something went wrong.