diff --git a/agenta-web/src/code_snippets/endpoints/fetch_config/curl.ts b/agenta-web/src/code_snippets/endpoints/fetch_config/curl.ts index cfb9976a89..0f651484e2 100644 --- a/agenta-web/src/code_snippets/endpoints/fetch_config/curl.ts +++ b/agenta-web/src/code_snippets/endpoints/fetch_config/curl.ts @@ -1,6 +1,8 @@ -export default function cURLCode(uri: string, config_url: string, params: string): string { - return `curl -X POST ${uri} \ --H "Content-Type: application/json" \ --d '${params}' -` +export default function cURLCode(baseId: string, env_name: string): string { + return ` + curl -X GET "https://cloud.agenta.ai/api/configs?base_id=${baseId}&environment_name=${env_name}" \ + -H "Authorization: Bearer YOUR_API_KEY" \ + -H "Content-Type: application/json" \ + --connect-timeout 60 + ` } diff --git a/agenta-web/src/code_snippets/endpoints/fetch_config/python.ts b/agenta-web/src/code_snippets/endpoints/fetch_config/python.ts index 977876984a..8aa5b99d2f 100644 --- a/agenta-web/src/code_snippets/endpoints/fetch_config/python.ts +++ b/agenta-web/src/code_snippets/endpoints/fetch_config/python.ts @@ -1,21 +1,10 @@ -export default function pythonCode(uri: string, config_url: string, params: string): string { +export default function pythonCode(baseId: string, env_name: string): string { return ` -import requests -import json + # os.environ["AGENTA_API_KEY"] = "your_api_key" # Only when using cloud + # os.environ["HOST"] = "https://cloud.agenta.ai" -url = "${uri}" -config_url = "${config_url}" - -config_response = requests.get(config_url) -config_data = config_response.json() - -params = ${params} -params.update(config_data) - -response = requests.post(url, json=params) - -data = response.json() - -print(json.dumps(data, indent=4)) -` + from agenta import Agenta + ag = Agenta() + ag.get_config(base_id="${baseId}", environment="${env_name}", cache_timeout=600) # timeout 300 per default + ` } diff --git a/agenta-web/src/code_snippets/endpoints/fetch_config/typescript.ts b/agenta-web/src/code_snippets/endpoints/fetch_config/typescript.ts index 1f217c47a2..8632f8dc57 100644 --- a/agenta-web/src/code_snippets/endpoints/fetch_config/typescript.ts +++ b/agenta-web/src/code_snippets/endpoints/fetch_config/typescript.ts @@ -1,19 +1,44 @@ import {js as beautify} from "js-beautify" -export default function tsCode(uri: string, config_url: string, params: string): string { +export default function tsCode(baseId: string, env_name: string): string { const codeString = ` - const generate = async () => { - try { - const config_response = await axios.get("${config_url}"); - let params = ${params} - const response = await axios.post("${uri}", {...params, ...config_response.data}); - console.log(response.data); - } catch (error) { - console.error(error); - } - }; + import axios from 'axios'; - generate(); + const getConfig = async (baseId: string, environmentName = null) => { + try { + const baseUrl = 'https://cloud.agenta.ai/api'; + const params = { + base_id: baseId, + environment_name: environmentName + }; + + const response = await axios.get(baseUrl + "/configs", { + params: params, + headers: { + 'Authorization': "Bearer YOUR_API_KEY", + 'Content-Type': 'application/json' + }, + timeout: 60000 + }); + + if (response.status >= 200 && response.status < 300) { + return response.data; + } else if (response.status === 422) { + throw new Error(JSON.stringify(response.data)); + } + } catch (error) { + if (error.response) { + console.error("API Error: " + error.response.status, error.response.data); + } else if (error.request) { + console.error('API Error: No response received', error.request); + } else { + console.error('Error', error.message); + } + throw error; + } + }; + + getConfig('${baseId}', '${env_name}').then(console.log).catch(console.error); ` const formattedCodeString = beautify(codeString) diff --git a/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx b/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx index 7ef34dfa3c..a128a4a8d9 100644 --- a/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx @@ -115,8 +115,8 @@ export default function VariantEndpoint() { const {inputParams, isChatVariant, isLoading, isError, error} = useVariant(appId, variant!) const createParams = ( inputParams: Parameter[] | null, + environmentName: string, value: string | number, - environmentName?: string, ) => { let mainParams: GenericObject = {} let secondaryParams: GenericObject = {} @@ -139,7 +139,9 @@ export default function VariantEndpoint() { mainParams["inputs"] = secondaryParams } - return JSON.stringify({...mainParams, environment: environmentName}, null, 2) + mainParams["environment"] = environmentName + + return JSON.stringify(mainParams, null, 2) } if (isVariantsError) { @@ -160,24 +162,17 @@ export default function VariantEndpoint() { ) } - const invokeLlmAppParams = createParams( - inputParams, - "add_a_value", - selectedEnvironment?.name || "none", - ) - - const fetchConfigParams = createParams(inputParams, "add_a_value") - + const params = createParams(inputParams, selectedEnvironment?.name || "none", "add_a_value") const invokeLlmAppCodeSnippet: Record = { - Python: invokeLlmApppythonCode(uri!, invokeLlmAppParams), - cURL: invokeLlmAppcURLCode(uri!, invokeLlmAppParams), - TypeScript: invokeLlmApptsCode(uri!, invokeLlmAppParams), + Python: invokeLlmApppythonCode(uri!, params), + cURL: invokeLlmAppcURLCode(uri!, params), + TypeScript: invokeLlmApptsCode(uri!, params), } const fetchConfigCodeSnippet: Record = { - Python: fetchConfigpythonCode(uri!, uri!, fetchConfigParams), - cURL: fetchConfigcURLCode(uri!, uri!, fetchConfigParams), - TypeScript: fetchConfigtsCode(uri!, uri!, fetchConfigParams), + Python: fetchConfigpythonCode(variant.baseId, selectedEnvironment?.name!), + cURL: fetchConfigcURLCode(variant.baseId, selectedEnvironment?.name!), + TypeScript: fetchConfigtsCode(variant.baseId, selectedEnvironment?.name!), } const items: CollapseProps["items"] = [