Skip to content
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

feat(wren-ai-service): integrate dspy into wrenAI #805

Merged
merged 16 commits into from
Nov 9, 2024

Conversation

tedyyan
Copy link
Contributor

@tedyyan tedyyan commented Oct 23, 2024

======================= 1 =====================
================ Build the module =================

use eval.py and the spider2 v1 dataset to train and optimize a dspy module (https://github.com/taoyds/spider/tree/master/evaluation_examples/examples)
The prediction_eval_ask_9df57d69-250c-4a10-b6a5-6595509fed6b_2024_10_23_132136.toml is a predict dataset without dspy

wren-ai-service/eval/prompt_optimizer.py --training-dataset spider_car_1_eval_dataset.toml --file prediction_eval_ask_9df57d69-250c-4a10-b6a5-6595509fed6b_2024_10_23_132136.toml

output: eval/optimized/AskGenerationV1_optimized_2024_10_21_181426.json

====================== 2 =======================
=================Prediction =================

  1. put the trained dspy module into an environment variable DSPY_OPTIMAZED_MODEL
export DSPY_OPTIMAZED_MODEL=eval/optimized/AskGenerationV1_optimized_2024_10_21_181426.json
  1. start predict get the predicted result
just predict eval/dataset/spider_car_1_eval_dataset.toml
  1. output
outputs/predictions/prediction_eval_ask_f5103405-09b2-448c-829d-cedd3c3b12d0_2024_10_22_184950.toml

====================== 3 =======================
=============== Evaluate =========================

  1. Start to evaluate according to the predicted result
just eval prediction_eval_ask_f5103405-09b2-448c-829d-cedd3c3b12d0_2024_10_22_184950.toml

image

Notes:
wren-ai-service/eval/prompt_optimizer.py can be improved by incorporating additional training examples or use other modules in dspy

Thanks for @cyyeh guide and codes, most of the PR's code are borrowed from his branch chore/ai-service/dspy

@tedyyan tedyyan mentioned this pull request Oct 23, 2024
@tedyyan tedyyan marked this pull request as ready for review October 24, 2024 15:23
@cyyeh cyyeh self-requested a review October 29, 2024 01:59
async def generate_sql(prompt: dict, generator: Any) -> dict:
logger.debug(f"prompt: {orjson.dumps(prompt, option=orjson.OPT_INDENT_2).decode()}")
return await generator.run(prompt=prompt.get("prompt"))
async def generate_sql(prompt: dict, generator: Any, dspy_module: Any) -> dict:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tedyyan could you help figure out if dspy_module supports async?

class SQLGeneration(BasicPipeline):
def __init__(
self,
llm_provider: LLMProvider,
engine: Engine,
**kwargs,
):
self.dspy_module = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, could you explain to me what do these lines of code mean?

Copy link
Member

@cyyeh cyyeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tedyyan thanks for your contribution. I think we can schedule a time to discuss this pr

@cyyeh cyyeh added module/ai-service ai-service related ci/ai-service ai-service related labels Nov 8, 2024
@cyyeh cyyeh changed the title integrate dspy into wrenAI feat(wren-ai-service): integrate dspy into wrenAI Nov 8, 2024
@tedyyan
Copy link
Contributor Author

tedyyan commented Nov 8, 2024

poetry lock —no-update

Copy link
Member

@cyyeh cyyeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution

@cyyeh cyyeh merged commit 9f3afa5 into Canner:main Nov 9, 2024
3 of 4 checks passed
cyyeh added a commit that referenced this pull request Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/ai-service ai-service related module/ai-service ai-service related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants