Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Agenta-AI/agenta into featu…
Browse files Browse the repository at this point in the history
…re/cloud_188-handle-large-datasets-for-open-api
  • Loading branch information
MohammedMaaz committed Dec 11, 2023
2 parents 4ae1b9f + 181e121 commit 1c25516
Show file tree
Hide file tree
Showing 36 changed files with 507 additions and 312 deletions.
1 change: 1 addition & 0 deletions agenta-backend/agenta_backend/routers/evaluation_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ async def create_evaluation_scenario(
"/{evaluation_id}/evaluation_scenario/{evaluation_scenario_id}/{evaluation_type}/"
)
async def update_evaluation_scenario_router(
evaluation_id: str,
evaluation_scenario_id: str,
evaluation_type: EvaluationType,
evaluation_scenario: EvaluationScenarioUpdate,
Expand Down
1 change: 0 additions & 1 deletion agenta-web/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default defineConfig({
baseUrl: "http://localhost",
defaultCommandTimeout: 30000,
requestTimeout: 10000,
specPattern: ["*/e2e/smoke-tests.cy.ts", "*/e2e/app-navigation.cy.ts"],
},
env: {
baseApiURL: "http://localhost/api",
Expand Down
13 changes: 7 additions & 6 deletions agenta-web/cypress/e2e/ab-testing-evaluation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ describe("A/B Testing Evaluation workflow", () => {

cy.clickLinkAndWait('[data-cy="start-new-evaluation-button"]')
cy.url().should("include", "/human_a_b_testing")
cy.get('[data-cy="evalInstructionsShown-ok-btn"]').click()

cy.get('[data-cy="abTesting-app-variant-vote-button"]').should("not.exist")
cy.get('[data-cy="abTesting-both-bad-vote-button"]').should("not.exist")
cy.wait(1000)
cy.get('[data-cy="abTesting-run-all-button"]').click()
cy.get('[data-cy^="abTesting-app-variant-1-vote-button"]').should("not.be.disabled")
cy.get('[data-cy^="abTesting-app-variant-2-vote-button"]').should("not.be.disabled")
cy.get('[data-cy^="abTesting-both-bad-vote-button"]').should("not.be.disabled")

cy.get('[data-cy="abTesting-app-variant-1-vote-button-0"]').click()
cy.get('[data-cy="abTesting-app-variant-2-vote-button-1"]').click()
cy.get('[data-cy="abTesting-both-bad-vote-button-2"]').click()
cy.get('[data-cy="abTesting-app-variant-vote-button"]').eq(0).click()
cy.get('[data-cy="abTesting-app-variant-vote-button"]').eq(1).click()
cy.get('[data-cy="abTesting-both-bad-vote-button"]').click()
})
})

Expand Down
2 changes: 1 addition & 1 deletion agenta-web/cypress/e2e/playground.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("Playground Prompt Test", function () {
})

it("Should test prompt functionality in the Playground", () => {
cy.get('[data-cy="testview-input-parameters-0"]').type("Germany")
cy.get('[data-cy^="testview-input-parameters"]').eq(0).type("Germany")
cy.get('[data-cy="testview-input-parameters-run-button"]').click()
cy.get('[data-cy="testview-input-parameters-result"]').should("contain.text", "Loading...")
cy.get('[data-cy="testview-input-parameters-result"]').should(
Expand Down
24 changes: 6 additions & 18 deletions agenta-web/cypress/e2e/testset.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,12 @@ describe("Testsets crud and UI functionality", () => {
cy.get('[data-cy="testset-name-input"]').type(testsetName)
cy.get(".ag-row").should("have.length", 3)
countries.forEach((country, index) => {
cy.get(".ag-row")
.eq(index)
.within(() => {
cy.get("div.ag-cell")
.eq(1)
.within(() => {
cy.get("span").eq(0).dblclick()
cy.get(".ag-input-field-input").type(country.country)
})
cy.get("div.ag-cell")
.eq(2)
.within(() => {
cy.get("span").eq(0).dblclick()
cy.get(".ag-input-field-input").type(
`The capital of ${country.country} is ${country.capital}.`,
)
})
})
cy.get(`.ag-center-cols-container .ag-row[row-index="${index}"]`).within(() => {
cy.get(".ag-cell").eq(1).type(country.country)
cy.get(".ag-cell")
.eq(2)
.type(`The capital of ${country.country} is ${country.capital}.`)
})
})
cy.intercept("/api/testsets/*").as("saveTestsetRequest")
cy.get('[data-cy="testset-save-button"]').click()
Expand Down
26 changes: 7 additions & 19 deletions agenta-web/cypress/support/commands/evaluations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Cypress.Commands.add("createVariant", () => {
})
})

cy.get('[data-cy="create-app-button"]').first().click()
cy.get('[data-cy^="create-app-button"]').eq(1).click()
const appName = randString(5)

cy.get('[data-cy="enter-app-name-modal"]')
Expand Down Expand Up @@ -66,24 +66,12 @@ Cypress.Commands.add("createVariantsAndTestsets", () => {

cy.get(".ag-row").should("have.length", 3)
countries.forEach((country, index) => {
cy.get(".ag-row")
.eq(index)
.within(() => {
cy.get("div.ag-cell")
.eq(1)
.within(() => {
cy.get("span").eq(0).dblclick()
cy.get(".ag-input-field-input").type(country.country)
})
cy.get("div.ag-cell")
.eq(2)
.within(() => {
cy.get("span").eq(0).dblclick()
cy.get(".ag-input-field-input").type(
`The capital of ${country.country} is ${country.capital}.`,
)
})
})
cy.get(`.ag-center-cols-container .ag-row[row-index="${index}"]`).within(() => {
cy.get(".ag-cell").eq(1).type(country.country)
cy.get(".ag-cell")
.eq(2)
.type(`The capital of ${country.country} is ${country.capital}.`)
})
})

cy.get('[data-cy="testset-save-button"]').click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ const SingleModelEvaluationTable: React.FC<EvaluationTableProps> = ({
type="primary"
onClick={runAllEvaluations}
size="large"
data-cy="abTesting-run-all-button"
data-cy="single-model-run-all-button"
>
Run All
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const ComparisonVote: React.FC<ComparisonVoteProps> = ({variants, onChange, valu
onClick={getOnClick(variant.variantId)}
type={value === variant.variantId ? "primary" : undefined}
danger
data-cy="abTesting-app-variant-vote-button"
>
{String.fromCharCode(65 + ix)}: {variant.variantName}
</Button>
Expand All @@ -106,6 +107,7 @@ const ComparisonVote: React.FC<ComparisonVoteProps> = ({variants, onChange, valu
type={value === badId ? "primary" : undefined}
key={badId}
onClick={getOnClick(badId)}
data-cy="abTesting-both-bad-vote-button"
>
Both are bad
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const EvaluationCardView: React.FC<Props> = ({
</li>
</ol>
),
okText: "Ok",
okText: <span data-cy="evalInstructionsShown-ok-btn">Ok</span>,
cancelText: null,
width: 500,
onCancel: () => (opened.current = false),
Expand Down
53 changes: 53 additions & 0 deletions docs/cli/init.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: "agenta init"
description: "Initialize a new project"
---


```bash
agenta init
```

# Description


The init command initializes a new agenta project. Users can define the application's name and select the agenta platform host (either local or cloud).

This command creates a blank project in the backend and generates a config.toml file for configuration settings.

<Info>This command creates a `project.toml` file containing all the information about your project</Info>

# Usage

When running `agenta init` you will prompted the following questions:

### Project name
```bash
? Please enter the app name
```

Enter the app/project name

### Agenta host
```bash
? Where are you running agenta? (Use arrow keys)
» On agenta cloud
On my local machine
On a remote machine
```

Here you can select where the agenta platform is hosted.
- Select cloud, in case you are using agenta cloud ([https://cloud.agenta.ai](https://cloud.agenta.ai)). In that case you will prompted to enter your API key. You can get these from the [agenta cloud configuration](https://cloud.agenta.ai/settings?tab=apiKeys).
- Select local machine if you are running the OSS version of agenta on your local machine ([http://localhost](http://localhost))
- Select remote machine, in case you are running the OSS version of agenta on a remote machine. In that case you will prompted to enter the remote machine URL.

<Info> In case you are running agenta enterprise, please refer to the enterprise documentation on how to set up your agenta project</Info>

### Start from scratch or from a template
```bash
? How do you want to initialize your app? (Use arrow keys)
» Blank App
Start from template
```

Chose blank app to start from scratch (write your own code) or start from template to use one of the agenta templates.
24 changes: 24 additions & 0 deletions docs/cli/install.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: "Install"
description: "Agenta's CLI enables developers to easily create, evaluate, and deploy LLM apps from code. Install it here"
---

# Installation

The agenta CLI can be easily installed through pip:

```bash
pip install -U agenta
```

# Quick usage guide

<CardGroup cols={2}>
<Card title="Quick Start" icon="circle-play" href="/cli/quick-usage">
Get an overview of the main commands and capabilities of agenta CLI
</Card>
<Card title="Tutorial" icon="books" href="/quickstart/getting-started-code">
Jump into a tutorial deploying an LLM app from code using agenta CLI

</Card>
</CardGroup>
46 changes: 46 additions & 0 deletions docs/cli/quick-usage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "Quick usage"
description: "Deploy and test LLM apps using agenta CLI"
---


The Agenta CLI is a tool used to manage LLM app variants used in Agenta. It allows you to create new apps and deploy variants to the Agenta platform.

## Create an application / project

To use the agenta CLI, first create a new folder for each project / application.

```bash
mkdir my_app
```

Next, initialize the project in agenta by running

```bash
agenta init
```

agenta init creates an empty project in the agenta platform (or populates it on one of the templates).

## Write the code [optional]
Depending whether you initialized the project with a template or not, you may need to write the code for your variant.
The code for your new variant in a .py file. The file should contain a function marked with the `@ag.entrypoint` decorator.

Here is an example
```python

import agenta as ag

ag.config.register_default(prompt="Translate {sentence} to {language})

@ag.entrypoint
def translate(sentence:str, language:str):
### add here openai call logic
```
## Serve the application

```bash
agenta variant serve myapp.py
```

This command deploys a new variant to the Agenta platform. It processes the code in the specified folder, with `myapp.py` as the entrypoint. This command builds a Docker image and deploys a container based on it. As a result, the variant becomes accessible in the web UI, allowing for prediction generation and API calls. The variant is named as `myapp.default` in the UI.
14 changes: 14 additions & 0 deletions docs/cli/variant_list.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "agenta variant list"
description: "List the variants for an application"
---

```bash
agenta variant list
```

# Description
The `list` command displays all the variants of your app that are currently available in the backend.

<Warning> The `variant list` command can only be run in a directory where the `config.toml` generated by `agenta init` is present. </Warning>

15 changes: 15 additions & 0 deletions docs/cli/variant_remove.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "agenta variant remove"
description: "Removes a variant from an app/project"
---

```bash
agenta variant remove
```

# Description

`variant remove` removes a variant from an app/project. It is called without any argument. The list of variants in the app/project is displayed and the user is prompted to select one of them to remove.


<Warning> The `variant remove` command can only be run in a directory where the `config.toml` generated by `agenta init` is present. </Warning>
31 changes: 31 additions & 0 deletions docs/cli/variant_serve.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: "agenta variant serve"
description: "Serve an application to the agenta platform"
---

```bash
agenta variant serve app_name.py
```

# Description
The `serve` command deploys the code of an app to the agenta platform. The command packages the code in the .py file along with any additional files in the same directory and deploy them on the agenta platform. Once deployed, the variant becomes accessible the web UI. It can ehtn be further deployed to a staging or production environment as an API endpoint.

In the agenta UI, the deployed variant is initially named `app_name.default` where `app_name` is the name of the python file deployed and `default` the default configuration. Creating a new configuration `someconfig` (either from the UI or from CLI), will result in the creation of corresponding new variant, named `app_name.someconfig`.


<Warning> The code in `app_name.py` needs to include an entrypoint function. This function should be marked with the `@agenta.entrypoint` decorator. </Warning>

Below is a brief example of a valid `app_name.py` file:

```python

import agenta as ag

ag.config.register_default(prompt="Translate {sentence} to {language})

@ag.entrypoint
def translate(sentence:str, language:str):
### add here openai call logic
```

<Warning> The `variant serve` command can only be run in a directory where the `config.toml` generated by `agenta init` is present.</Warning>
2 changes: 0 additions & 2 deletions docs/contributing/file-issue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
title: How to File an Issue
---

# How to File an Issue

Filing an issue is an important step in helping us improve our project. Please follow these steps and provide the requested information when reporting an issue.

## Reporting a Bug
Expand Down
42 changes: 42 additions & 0 deletions docs/howto/use-a-custom-llm.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: How to use a Custom LLM in agenta
description: 'Learn how to write an LLM application that uses a custom LLM'
---

Using a custom LLM in Agenta is straightforward. The process involves writing the code for a custom application using the SDK, which then calls the LLM.

Below is the structure of a custom application that calls a [vllm hosted model on an API server](https://docs.vllm.ai/en/latest/getting_started/quickstart.html#api-server):

```python

import agenta as ag
import requests

default_prompt = "Please write a joke about {subject}"

url = "https://<api-server-url>/generate"
ag.config.default(prompt=default_prompt,
temperature=0.8)

@ag.entrypoint
def generate(subject:str)->str:
prompt = config.prompt.format(subject=subject)
data = {
"prompt": prompt,
"temperature": config.temperature
}
response = requests.post(url, data=json.dumps(data))
return response.json()
```

The above code is a simple LLM app that generates jokes about a given subject, using a vLLM hosted model. It is structured as follows:

`ag.config.default` sets the default values for the configuration of the LLM application. In this example, the default prompt is "Please write a joke about {subject}", and the temperature is set at 0.8.

The `@ag.entrypoint` decorator marks the function that will be called. The function `generate` accepts a subject as input and returns a joke as output. It calls the vLLM hosted model using the requests library.

To call any other LLM, you need to set up the configuration for the LLM (prompt, temperature, etc.) and then call the LLM in the main function.

After writing the code, it can be deployed using the CLI, as described in the [command line reference](/cli/quick-usage). This can be done by running `agenta init` followed by `agenta variant serve app.py` in the code folder.

<Warning> Note that if the LLM is hosted on your local machine and not accessible from outside, you will need to [self-host agenta locally](self-host/host-locally) to be able to call the LLM from the LLm app. </Warning>
Loading

0 comments on commit 1c25516

Please sign in to comment.