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(blocks): Add AI/ML API support to LLM blocks #9163

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from

Conversation

waterstark
Copy link

Changes 🏗️

  • Added basic functionality to enable users to send requests to our models.
  • Added instructions for users on how to use the AI/ML API in AutoGPT.

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • The API key has been successfully added and saved to the user's profile.
    • Sending requests to each model provided by us, enabling users to test them in a project with various max_tokens parameter values and other configurations.
Example test plan
  • Create from scratch and execute an agent with at least 3 blocks
  • Import an agent from file upload, and confirm it executes correctly
  • Upload agent to marketplace
  • Import an agent from marketplace and confirm it executes correctly
  • Edit an agent from monitor, and confirm it executes correctly

For configuration changes:

  • .env.example is updated or already compatible with my changes
  • docker-compose.yml is updated or already compatible with my changes
  • I have included a list of my configuration changes in the PR description (under Changes)
Examples of configuration changes
  • Changing ports
  • Adding new services that need to communicate with each other
  • Secrets or environment variable changes
  • New or infrastructure changes such as databases

@waterstark waterstark requested a review from a team as a code owner January 1, 2025 13:06
@waterstark waterstark requested review from aarushik93 and majdyz and removed request for a team January 1, 2025 13:06
@CLAassistant
Copy link

CLAassistant commented Jan 1, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

github-actions bot commented Jan 1, 2025

This PR targets the master branch but does not come from dev or a hotfix/* branch.

Automatically setting the base branch to dev.

@github-actions github-actions bot changed the base branch from master to dev January 1, 2025 13:06
@github-actions github-actions bot added documentation Improvements or additions to documentation Forge platform/frontend AutoGPT Platform - Front end platform/backend AutoGPT Platform - Back end platform/blocks size/l labels Jan 1, 2025
Copy link

qodo-merge-pro bot commented Jan 1, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 Security concerns

API Key Exposure:
The AIML API key is stored in environment variables and configuration files. While this is a common practice, ensure the .env file and configuration files have proper access restrictions and are not accidentally committed to version control.

⚡ Recommended focus areas for review

Error Handling

The AIML provider implementation lacks proper error handling for API failures and rate limits. Should add try-catch blocks and handle common API errors.

elif provider == "aiml":
    client = openai.OpenAI(
        base_url="https://api.aimlapi.com/v2",
        api_key=credentials.api_key.get_secret_value(),
    )

    completion = client.chat.completions.create(
        model=llm_model.value,
        messages=prompt,  # type: ignore
        max_tokens=max_tokens,
    )

    # response = completion.choices[0].message.content
    return (
        completion.choices[0].message.content or "",
        completion.usage.prompt_tokens if completion.usage else 0,
        completion.usage.completion_tokens if completion.usage else 0,
    )
else:
Token Counting

Using GPT-3.5-turbo tokenizer as a hack for AIML models may lead to incorrect token counting since different models can have different tokenization schemes.

def get_tokenizer(self, model_name: AimlModelName) -> ModelTokenizer[Any]:
    # HACK: No official tokenizer is available for AIML
    return tiktoken.encoding_for_model("gpt-3.5-turbo")
Model Validation

The code should validate that the provided model name exists in the AIML provider's model list before making API calls.

completion = client.chat.completions.create(
    model=llm_model.value,
    messages=prompt,  # type: ignore
    max_tokens=max_tokens,
)

Copy link

netlify bot commented Jan 1, 2025

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit ed951b0
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/6780ec485524ec0008a83cd3

Copy link

codecov bot commented Jan 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (dev@1ce1918). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             dev    #9163   +/-   ##
======================================
  Coverage       ?   33.94%           
======================================
  Files          ?       16           
  Lines          ?     1258           
  Branches       ?      190           
======================================
  Hits           ?      427           
  Misses         ?      804           
  Partials       ?       27           
Flag Coverage Δ
Linux 33.94% <ø> (?)
Windows 33.94% <ø> (?)
autogpt-agent 33.94% <ø> (?)
macOS 33.94% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

netlify bot commented Jan 2, 2025

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
🔨 Latest commit ed951b0
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs-dev/deploys/6780ec481fae980008221aea

@@ -35,6 +35,7 @@
ProviderName.OLLAMA,
ProviderName.OPENAI,
ProviderName.OPEN_ROUTER,
ProviderName.AIML,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ProviderName.AIML,
ProviderName.AIML_API,

same for all other occurrences

Copy link
Member

@Pwuts Pwuts left a comment

Choose a reason for hiding this comment

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

Thanks for taking the effort to submit this integration!

A quick scan of your PR shows a couple of issues:

  • Unrelated formatting changes in multiple files
  • Changes in classic/forge - is this intentional? The added AimlProvider isn't used in autogpt_platform/backend/backend/blocks/llm.py. The CI also fails because there are type issues in your added code in classic/forge.

CI should pass once you remove the changes in classic/forge. Once you do this, and address the other comments, I'll take a look again. The changes in backend look pretty good. :)

Also, please update and fulfill the checklist in the PR description.

@Pwuts Pwuts changed the title Integration with aiml feat(blocks): Add AI/ML API support to LLM blocks Jan 6, 2025
@@ -175,6 +175,19 @@ If you don't know which to choose, you can safely go with OpenAI*.
[anthropic/models]: https://docs.anthropic.com/en/docs/models-overview


### AI/ML API
1. Make sure you have credits in your account: [Billing -> View Usage](https://aimlapi.com/app/billing?utm_source=autogpt&utm_medium=github&utm_campaign=integration)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove all the utm's please

Copy link

@OctavianTheI OctavianTheI Jan 7, 2025

Choose a reason for hiding this comment

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

hi!
We need the utms to evaluate the traffic from the project, and allocate the developer resources

(basically, I use them to prove to my team that open-source is important, and to grow our open-source integrators part of the team)

Copy link
Member

Choose a reason for hiding this comment

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

Hey @OctavianTheI - happy to discuss this
I've booked a call with you guys tomorrow via your website.

@github-actions github-actions bot removed the Forge label Jan 8, 2025
@@ -4,6 +4,7 @@
# --8<-- [start:ProviderName]
class ProviderName(str, Enum):
ANTHROPIC = "anthropic"
AIML_API = "aiml"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AIML_API = "aiml"
AIML_API = "aiml_api"

@@ -433,6 +445,23 @@ def llm_call(
response.usage.prompt_tokens if response.usage else 0,
response.usage.completion_tokens if response.usage else 0,
)
elif provider == "aiml":
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
elif provider == "aiml":
elif provider == "aiml_api":

@@ -49,6 +49,13 @@
title="Use Credits for OpenAI",
expires_at=None,
)
aiml_credentials = APIKeyCredentials(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
aiml_credentials = APIKeyCredentials(
aiml_api_credentials = APIKeyCredentials(

@@ -49,6 +49,13 @@
title="Use Credits for OpenAI",
expires_at=None,
)
aiml_credentials = APIKeyCredentials(
id="aad82a89-9794-4ebb-977f-d736aa5260a3",
provider="aiml",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
provider="aiml",
provider="aiml_api",

@@ -266,6 +266,7 @@ class Secrets(UpdateTrackingModel["Secrets"], BaseSettings):
)

openai_api_key: str = Field(default="", description="OpenAI API key")
aiml_api_key: str = Field(default="", description="AI/ML API key")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
aiml_api_key: str = Field(default="", description="AI/ML API key")
aiml_api_key: str = Field(default="", description="'AI/ML API' key")

@@ -103,6 +103,7 @@ export default function PrivatePage() {
"6b9fc200-4726-4973-86c9-cd526f5ce5db", // Replicate
"53c25cb8-e3ee-465c-a4d1-e75a4c899c2a", // OpenAI
"24e5d942-d9e3-4798-8151-90143ee55629", // Anthropic
"aad82a89-9794-4ebb-977f-d736aa5260a3", // AI/ML
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"aad82a89-9794-4ebb-977f-d736aa5260a3", // AI/ML
"aad82a89-9794-4ebb-977f-d736aa5260a3", // AI/ML API

@@ -52,6 +52,7 @@ export const providerIcons: Record<
github: FaGithub,
google: FaGoogle,
groq: fallbackIcon,
aiml: fallbackIcon,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
aiml: fallbackIcon,
aiml_api: fallbackIcon,

@@ -102,6 +102,7 @@ export type CredentialsType = "api_key" | "oauth2";
// --8<-- [start:BlockIOCredentialsSubSchema]
export const PROVIDER_NAMES = {
ANTHROPIC: "anthropic",
AIML: "aiml",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AIML: "aiml",
AIML_API: "aiml_api",

@@ -16,6 +16,7 @@ const CREDENTIALS_PROVIDER_NAMES = Object.values(

// --8<-- [start:CredentialsProviderNames]
const providerDisplayNames: Record<CredentialsProviderName, string> = {
aiml: "AI/ML",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
aiml: "AI/ML",
aiml_api: "AI/ML API",

Copy link
Member

@Pwuts Pwuts Jan 9, 2025

Choose a reason for hiding this comment

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

Please git reset --hard dev -- classic docs/content/classic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation platform/backend AutoGPT Platform - Back end platform/blocks platform/frontend AutoGPT Platform - Front end Review effort [1-5]: 4 size/l
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants