-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fe362e
commit b2e3801
Showing
28 changed files
with
821 additions
and
196 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import dspy | ||
|
||
from pydantic import BaseModel, Field | ||
from typing import Optional, Dict, Any | ||
|
||
from rdddy.generators.gen_pydantic_instance import GenPydanticInstance | ||
|
||
api_description = """ | ||
Imagine a digital portal where users can inquire about meteorological conditions. | ||
This portal is accessible through a web interface that interacts with a backend service. | ||
The service is invoked by sending a request to a specific endpoint. | ||
This request is crafted using a standard protocol for web communication. | ||
The endpoint's location is a mystery, hidden within the path '/forecast/today'. | ||
Users pose their inquiries by specifying a geographical area of interest, | ||
though the exact format of this specification is left to the user's imagination. | ||
Upon successful request processing, the service responds with a structured | ||
summary of the weather, encapsulating details such as temperature, humidity, | ||
and wind speed. However, the structure of this response and the means of | ||
accessing the weather summary are not explicitly defined. | ||
""" | ||
|
||
|
||
class APIEndpoint(BaseModel): | ||
method: str = Field(..., description="HTTP method of the API endpoint") | ||
url: str = Field(..., description="URL of the API endpoint") | ||
description: str = Field( | ||
..., description="Description of what the API endpoint does" | ||
) | ||
response: str = Field(..., description="Response from the API endpoint") | ||
query_params: Optional[Dict[str, Any]] = Field(None, description="Query parameters") | ||
|
||
|
||
def main(): | ||
lm = dspy.OpenAI(max_tokens=1000) | ||
dspy.settings.configure(lm=lm) | ||
|
||
gpm = GenPydanticInstance(root_model=APIEndpoint) | ||
result = gpm.forward(prompt=api_description) | ||
print(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 |
---|---|---|
|
@@ -47,6 +47,7 @@ def test_forward_syntax_error( | |
with pytest.raises(ValueError): | ||
gen_python_primitive.forward("Create a list with syntax error") | ||
|
||
|
||
import inspect | ||
|
||
|
||
|
@@ -88,7 +89,21 @@ def test_forward_success( | |
# mock_literal_eval, mock_chain_of_thought, mock_predict, gen_python_primitive | ||
): | ||
# Setup mock responses | ||
response = {'first_name': 'Alex', 'last_name': 'Johnson', 'age': 35, 'email': '[email protected]', 'skills': ['Python', 'JavaScript', 'SQL'], 'address': {'street': '123 Main St', 'city': 'Springfield', 'state': 'IL', 'zip_code': '62704', 'country': 'USA'}, 'is_manager': False} | ||
response = { | ||
"first_name": "Alex", | ||
"last_name": "Johnson", | ||
"age": 35, | ||
"email": "[email protected]", | ||
"skills": ["Python", "JavaScript", "SQL"], | ||
"address": { | ||
"street": "123 Main St", | ||
"city": "Springfield", | ||
"state": "IL", | ||
"zip_code": "62704", | ||
"country": "USA", | ||
}, | ||
"is_manager": False, | ||
} | ||
# mock_predict.return_value.get.return_value = "['Jupiter', 'Saturn']" | ||
# mock_chain_of_thought.return_value.get.return_value = "['Jupiter', 'Saturn']" | ||
# mock_literal_eval.return_value = ["Jupiter", "Saturn"] | ||
|
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,56 @@ | ||
import typer | ||
|
||
app = typer.Typer() | ||
|
||
|
||
@app.command(name="generate_module") | ||
def generate_module(): | ||
"""Generates a new DSPy module with a specified name.""" | ||
# Command logic goes here | ||
print("This is the generate_module command.") | ||
|
||
|
||
@app.command(name="generate_signature") | ||
def generate_signature(): | ||
"""Creates a new signature class for defining input-output behavior in DSPy modules.""" | ||
# Command logic goes here | ||
print("This is the generate_signature command.") | ||
|
||
|
||
@app.command(name="generate_chainofthought") | ||
def generate_chainofthought(): | ||
"""Generates a ChainOfThought module with a standard question-answering signature.""" | ||
# Command logic goes here | ||
print("This is the generate_chainofthought command.") | ||
|
||
|
||
@app.command(name="generate_retrieve") | ||
def generate_retrieve(): | ||
"""Generates a Retrieve module for use in information retrieval tasks within DSPy.""" | ||
# Command logic goes here | ||
print("This is the generate_retrieve command.") | ||
|
||
|
||
@app.command(name="generate_teleprompter") | ||
def generate_teleprompter(): | ||
"""Creates a teleprompter setup for optimizing DSPy programs.""" | ||
# Command logic goes here | ||
print("This is the generate_teleprompter command.") | ||
|
||
|
||
@app.command(name="generate_example") | ||
def generate_example(): | ||
"""Generates an example structure for use in training and testing DSPy modules.""" | ||
# Command logic goes here | ||
print("This is the generate_example command.") | ||
|
||
|
||
@app.command(name="generate_assertion") | ||
def generate_assertion(): | ||
"""Generates a template for creating LM Assertions in DSPy programs.""" | ||
# Command logic goes here | ||
print("This is the generate_assertion command.") | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
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,61 @@ | ||
import pytest | ||
from typer.testing import CliRunner | ||
from metadspy.cli import app # Updated import statement | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_generate_module(): | ||
result = runner.invoke(app, ["generate_module"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_module command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_signature(): | ||
result = runner.invoke(app, ["generate_signature"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_signature command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_chainofthought(): | ||
result = runner.invoke(app, ["generate_chainofthought"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_chainofthought command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_retrieve(): | ||
result = runner.invoke(app, ["generate_retrieve"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_retrieve command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_teleprompter(): | ||
result = runner.invoke(app, ["generate_teleprompter"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_teleprompter command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_example(): | ||
result = runner.invoke(app, ["generate_example"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_example command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_assertion(): | ||
result = runner.invoke(app, ["generate_assertion"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_assertion command." in result.output | ||
) # Replace with specific expected output |
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,61 @@ | ||
import pytest | ||
from typer.testing import CliRunner | ||
from metadspy.cli import app # Updated import statement | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_generate_module(): | ||
result = runner.invoke(app, ["generate_module"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_module command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_signature(): | ||
result = runner.invoke(app, ["generate_signature"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_signature command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_chainofthought(): | ||
result = runner.invoke(app, ["generate_chainofthought"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_chainofthought command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_retrieve(): | ||
result = runner.invoke(app, ["generate_retrieve"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_retrieve command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_teleprompter(): | ||
result = runner.invoke(app, ["generate_teleprompter"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_teleprompter command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_example(): | ||
result = runner.invoke(app, ["generate_example"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_example command." in result.output | ||
) # Replace with specific expected output | ||
|
||
|
||
def test_generate_assertion(): | ||
result = runner.invoke(app, ["generate_assertion"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
"This is the generate_assertion command." in result.output | ||
) # Replace with specific expected output |
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,4 @@ | ||
2024-01-31 16:06:29,589 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for SignatureModel | ||
2024-01-31 16:06:30,434 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for SignatureModel | ||
2024-01-31 16:08:39,507 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for SignatureModel | ||
2024-01-31 16:08:43,071 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for SignatureModel |
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 |
---|---|---|
@@ -1,21 +1,22 @@ | ||
from pydantic import BaseModel, validator | ||
|
||
|
||
class FastAPIRouteModel(BaseModel): | ||
path_param: str | ||
query_param: int | ||
request_body: str | ||
|
||
@validator('path_param') | ||
@validator("path_param") | ||
def validate_path_param(cls, v): | ||
# validation logic | ||
return v | ||
|
||
@validator('query_param') | ||
@validator("query_param") | ||
def validate_query_param(cls, v): | ||
# validation logic | ||
return v | ||
|
||
@validator('request_body') | ||
@validator("request_body") | ||
def validate_request_body(cls, v): | ||
# validation logic | ||
return v | ||
return v |
Oops, something went wrong.