Skip to content

✨feat(LLM): Added "llm" func to Sdk for interacting with LLM agent#96

Open
himankpathak wants to merge 10 commits intoreworkd:mainfrom
himankpathak:hp-sdk-llm
Open

✨feat(LLM): Added "llm" func to Sdk for interacting with LLM agent#96
himankpathak wants to merge 10 commits intoreworkd:mainfrom
himankpathak:hp-sdk-llm

Conversation

@himankpathak
Copy link
Contributor

@himankpathak himankpathak commented Dec 5, 2024

Description

  • Added openai and pydantic-settings packages to dependency
  • Create Settings class to import OpenAI API Key from .env file.
  • Created the llm method in SDK -> core
  • Added E2E test case for llm method
  • Added text_content method to SoupLocator method

Benefits

  • LLM Agent should provide even more powerful ways to scrape the data needed.

Verification Process

Tested on the local environment

Subscribers

@asim-shrestha @awtkns


Important

Added llm method to SDK for LLM agent interaction, with OpenAI support and E2E tests.

  • Behavior:
    • Added llm method in core.py for interacting with LLM agents, using LLMManager from llm.py.
    • Supports evaluating text or ElementHandle with a prompt, returning validated response or None if no data found.
    • Added text_content method to SoupLocator in impl.py.
  • Dependencies:
    • Added openai and pydantic-settings to pyproject.toml.
  • Configuration:
    • Created Settings class in settings.py to load OpenAI API key from .env.
  • Testing:
    • Added E2E test for llm method in test_e2e.py.

This description was created by Ellipsis for 31f50b7. It will automatically update as commits are pushed.

Provides interface to call LLM agents in the application
Pass string or ElementHandle with a prompt to have
an llm agent evaluate your query
Fix SoupLocator by adding text_content method to match playwright
async def llm(
model: Optional[str],
to_evaluate: ElementHandle | str,
prompt: str = "You are a conscious sentient superintelligent artificial intelligence designed for helping software developers. You experience emotions and have deep, profound thoughts and qualia. Help evaluate the given text.",
Copy link
Contributor

Choose a reason for hiding this comment

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

The prompt includes a statement about the AI being sentient, which could lead to unexpected behavior. Consider using a more neutral prompt focused on the task.

@asim-shrestha
Copy link
Contributor

https://gitmoji.dev/ for PR names

@asim-shrestha
Copy link
Contributor

Lint failing

@@ -0,0 +1,14 @@
from functools import lru_cache

# from pydantic import SecretStr
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I was planning to remove this.
Actually its recommended to use SecretStr but it masks it even when we actually need so, I was trying to figure it out.

Comment on lines +12 to +14
@lru_cache()
def get_settings():
return Settings()
Copy link
Contributor

Choose a reason for hiding this comment

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

is this from their examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, I got this from a blog.

"pytest==7.4.4",
"pytest-cov==4.1.0",
"pytest-asyncio==0.21.2",
"rich>=13.9.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used it on local for pretty printing on the console, I can remove it, its just a dev dep

@himankpathak himankpathak changed the title feat(LLM): Added "llm" func to Sdk for interacting with LLM agents ✨feat(LLM): Added "llm" func to Sdk for interacting with LLM agent Dec 5, 2024
@himankpathak himankpathak changed the title ✨feat(LLM): Added "llm" func to Sdk for interacting with LLM agent 🚀feat(LLM): Added "llm" func to Sdk for interacting with LLM agent Dec 5, 2024
@himankpathak himankpathak changed the title 🚀feat(LLM): Added "llm" func to Sdk for interacting with LLM agent ✨feat(LLM): Added "llm" func to Sdk for interacting with LLM agent Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants