Skip to content

Commit

Permalink
Merge pull request #2304 from Agenta-AI/fix/in-app-auth-docs
Browse files Browse the repository at this point in the history
[Fix] clean up in-app auth docs and clean up in-app llm app URLs
  • Loading branch information
mmabrouk authored Nov 25, 2024
2 parents 3cb93d1 + 9aba679 commit fdc03ac
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 18 deletions.
3 changes: 1 addition & 2 deletions agenta-web/src/code_snippets/endpoints/fetch_config/curl.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export default function cURLCode(appName: string, env_name: string): string {
return `curl -L '${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/variants/configs/fetch' \\
-H "Authorization: Bearer YOUR_API_KEY" \\
-H 'Content-Type: application/json' \\
-H 'Accept: application/json' \\
-H "Authorization: ApiKey x.xxxxxxxx" \\ # Add your API key here, when using cloud
-d '{
"environment_ref": {
"slug": "${env_name}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default function pythonCode(appName: string, env_name: string): string {
import os
import agenta as ag
os.environ["AGENTA_API_KEY"] = "your_api_key" # Only when using cloud
os.environ["AGENTA_API_KEY"] = "x.xxxxxxxx" # Add you API key here, when using cloud
os.environ["AGENTA_HOST"] = "${process.env.NEXT_PUBLIC_AGENTA_API_URL}"
ag.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ const getConfig = async (appName: string, environmentSlug: string) => {
},
}, {
headers: {
'Authorization': "Bearer YOUR_API_KEY",
'Content-Type': 'application/json',
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': "ApiKey x.xxxxxxxx", // Add your API key here, when using cloud
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default function cURLCode(uri: string, params: string): string {
return `curl -X POST ${uri} \\
-H "Content-Type: application/json" \\
-H "Authorization: ApiKey x.xxxxxxxx" \\ # Add your API key here, when using cloud
-d '${params}'
`
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import json
url = "${uri}"
params = ${params}
headers = {
"Content-Type": "application/json",
"Authorization": "ApiKey x.xxxxxxxx", # Add your API key here, when using cloud
}
response = requests.post(url, json=params)
response = requests.post(url, json=params, headers=headers)
data = response.json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ export default function tsCode(uri: string, params: string): string {
const codeString = `import axios from 'axios';
const generate = async () => {
const response = await axios.post('${uri}', ${params});
const url = '${uri}';
const data = ${params};
const headers = {
"Content-Type": "application/json",
"Authorization": "ApiKey x.xxxxxxxx" // Add your API key here, when using cloud
};
const response = await axios.post(url, data, { headers });
console.log(response.data);
};
};
generate().catch(console.error);
generate().catch(console.error);
`

const formattedCodeString = beautify(codeString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {useVariant} from "@/lib/hooks/useVariant"
import {isDemo} from "@/lib/helpers/utils"
import {dynamicComponent} from "@/lib/helpers/dynamic"
import VariantPopover from "../variants/VariantPopover"
import {getCurrentProject} from "@/contexts/project.context"
import {useAppsData} from "@/contexts/app.context"

const DeploymentHistoryModal: any = dynamicComponent(
Expand Down Expand Up @@ -131,7 +130,6 @@ const DeploymentDrawer = ({
const [uri, setURI] = useState<string | null>(null)
const [variant, setVariant] = useState<Variant | null>(null)
const [isHistoryModalOpen, setIsHistoryModalOpen] = useState(false)
const {projectId} = getCurrentProject()

useEffect(() => {
loadURL(selectedEnvironment)
Expand All @@ -149,7 +147,7 @@ const DeploymentDrawer = ({
const loadURL = async (environment: Environment) => {
if (environment.deployed_app_variant_id) {
const url = await fetchAppContainerURL(appId, environment.deployed_app_variant_id)
setURI(`${url}/generate_deployed?project_id=${projectId}`)
setURI(`${url}/generate_deployed`)
}
}

Expand Down
4 changes: 1 addition & 3 deletions agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {useRouter} from "next/router"
import {useEffect, useState} from "react"
import {createUseStyles} from "react-jss"
import {useQueryParam} from "@/hooks/useQuery"
import {getCurrentProject} from "@/contexts/project.context"

const DeploymentHistory: any = dynamicComponent("DeploymentHistory/DeploymentHistory")

Expand Down Expand Up @@ -79,14 +78,13 @@ export default function VariantEndpoint() {
const appId = router.query.app_id as string
const [tab, setTab] = useQueryParam("tab", "overview")
const isOss = !isDemo()
const {projectId} = getCurrentProject()

// Load URL for the given environment
const [uri, setURI] = useState<string | null>(null)
const loadURL = async (environment: Environment) => {
if (environment.deployed_app_variant_id) {
const url = await fetchAppContainerURL(appId, environment.deployed_app_variant_id)
setURI(`${url}/generate_deployed?project_id=${projectId}`)
setURI(`${url}/generate_deployed`)
}
}

Expand Down
3 changes: 1 addition & 2 deletions agenta-web/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ export async function callVariant(
}

const appContainerURI = await fetchAppContainerURL(appId, undefined, baseId)
const {projectId} = getCurrentProject()
const jwt = await getJWT()

return axios
.post(`${appContainerURI}/generate?project_id=${projectId}`, requestBody, {
.post(`${appContainerURI}/generate`, requestBody, {
signal,
_ignoreError: ignoreAxiosError,
headers: {
Expand Down

0 comments on commit fdc03ac

Please sign in to comment.