-
Notifications
You must be signed in to change notification settings - Fork 1
Add math and learn-to-ask langchain demos #2
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
Conversation
Summary of ChangesHello @Kanaricc, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the project by integrating new Langchain-based workflows. It introduces a sophisticated 'learn-to-ask' medical assistant demo, complete with reward functions for evaluating question quality, and a dedicated math agent capable of solving problems. These additions broaden the framework's capabilities in handling complex agentic tasks and demonstrate practical applications of large language models, supported by necessary dependency updates and minor code cleanup. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces two new demonstration scripts utilizing langchain for a math agent and a 'learn-to-ask' agent. The changes primarily involve adding these new files and including langchain as a dependency. My review is focused on the new scripts, where I've identified opportunities for improvement. These include cleaning up unused imports, correcting a workflow name that seems to have been copied from another example, and addressing a more significant issue with the use of threading primitives in an asynchronous context. I have provided specific suggestions for these points to enhance code quality and correctness.
| _reward_semaphore = threading.Semaphore(16) | ||
|
|
||
| async def reward_fn_with_semaphore(*args, **kwargs): | ||
|
|
||
| get_sem_ok = False | ||
| while not get_sem_ok: | ||
| get_sem_ok = _reward_semaphore.acquire(blocking=False) | ||
| if not get_sem_ok: | ||
| await asyncio.sleep(1) | ||
|
|
||
| try: | ||
| fn_result = await reward_fn(*args, **kwargs) | ||
| finally: | ||
| _reward_semaphore.release() | ||
|
|
||
| return fn_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation uses threading.Semaphore with a polling loop (while not get_sem_ok...) in an asyncio context. This is inefficient as it involves busy-waiting. A more idiomatic and efficient approach for asynchronous code is to use asyncio.Semaphore, which integrates with the async with statement for cleaner and non-blocking synchronization.
| _reward_semaphore = threading.Semaphore(16) | |
| async def reward_fn_with_semaphore(*args, **kwargs): | |
| get_sem_ok = False | |
| while not get_sem_ok: | |
| get_sem_ok = _reward_semaphore.acquire(blocking=False) | |
| if not get_sem_ok: | |
| await asyncio.sleep(1) | |
| try: | |
| fn_result = await reward_fn(*args, **kwargs) | |
| finally: | |
| _reward_semaphore.release() | |
| return fn_result | |
| _reward_semaphore = asyncio.Semaphore(16) | |
| async def reward_fn_with_semaphore(*args, **kwargs): | |
| async with _reward_semaphore: | |
| return await reward_fn(*args, **kwargs) |
| import asyncio | ||
| import threading | ||
|
|
||
| from agentscope.message import Msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
|
|
||
| class ExampleLearn2Ask(Workflow): | ||
| name: str = "math_agent_workflow" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow name math_agent_workflow seems to be a copy-paste from another example. To improve clarity and avoid potential confusion, it should be renamed to something more descriptive of its actual function, like learn2ask_langchain_workflow.
| name: str = "math_agent_workflow" | |
| name: str = "learn2ask_langchain_workflow" |
| from loguru import logger | ||
| from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask | ||
| from openai.types.chat.chat_completion import ChatCompletion | ||
| from openai.types.chat import ChatCompletionMessageToolCall | ||
| from textwrap import dedent | ||
|
|
||
| import json | ||
| import asyncio | ||
| import requests | ||
| from langchain.agents import create_agent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file contains several unused imports, including loguru, openai.types, json, asyncio, and requests. Removing these will improve code readability and maintainability. It's also a good practice to group and order imports according to PEP 8.
| from loguru import logger | |
| from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask | |
| from openai.types.chat.chat_completion import ChatCompletion | |
| from openai.types.chat import ChatCompletionMessageToolCall | |
| from textwrap import dedent | |
| import json | |
| import asyncio | |
| import requests | |
| from langchain.agents import create_agent | |
| from textwrap import dedent | |
| from langchain.agents import create_agent | |
| from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask | |
No description provided.