Skip to content

Commit

Permalink
add ability to specify custom http headers in api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
adilhafeez committed Jan 29, 2025
1 parent a7feb6b commit a0db504
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions arch/arch_config_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ properties:
enum:
- GET
- POST
http_headers:
type: object
additionalProperties:
type: string
additionalProperties: false
required:
- name
Expand Down
1 change: 1 addition & 0 deletions crates/common/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pub struct EndpointDetails {
pub path: Option<String>,
#[serde(rename = "http_method")]
pub method: Option<HttpMethod>,
pub http_headers: Option<HashMap<String, String>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
18 changes: 13 additions & 5 deletions crates/prompt_gateway/src/stream_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,27 +317,35 @@ impl StreamContext {
};

let http_method = endpoint.method.unwrap_or_default().to_string();
let mut headers = vec![
let mut headers: HashMap<_, _> = [
(ARCH_UPSTREAM_HOST_HEADER, endpoint.name.as_str()),
(":method", &http_method),
(":path", &path),
(":authority", endpoint.name.as_str()),
("content-type", "application/json"),
("x-envoy-max-retries", "3"),
];
]
.into_iter()
.collect();

if self.request_id.is_some() {
headers.push((REQUEST_ID_HEADER, self.request_id.as_ref().unwrap()));
headers.insert(REQUEST_ID_HEADER, self.request_id.as_ref().unwrap());
}

if self.traceparent.is_some() {
headers.push((TRACE_PARENT_HEADER, self.traceparent.as_ref().unwrap()));
headers.insert(TRACE_PARENT_HEADER, self.traceparent.as_ref().unwrap());
}

// override http headers that are set in the prompt target
let http_headers = endpoint.http_headers.unwrap_or_default();
for (key, value) in http_headers.iter() {
headers.insert(key.as_str(), value.as_str());
}

let call_args = CallArgs::new(
ARCH_INTERNAL_CLUSTER_NAME,
&path,
headers,
headers.into_iter().collect(),
Some(tool_params_json_str.as_bytes()),
vec![],
Duration::from_secs(5),
Expand Down
9 changes: 6 additions & 3 deletions demos/currency_exchange/arch_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ listener:

llm_providers:
- name: gpt-4o
access_key: $OPENAI_API_KEY
access_key: $OPENAI_API_KEY1
provider_interface: openai
model: gpt-4o

Expand All @@ -33,6 +33,8 @@ prompt_targets:
endpoint:
name: frankfurther_api
path: /v1/latest?base=USD&symbols={currency_symbol}
http_headers:
Authorization: "Bearer $FRANKFURT_API_KEY"
system_prompt: |
You are a helpful assistant. Show me the currency symbol you want to convert from USD.
Expand All @@ -41,11 +43,12 @@ prompt_targets:
endpoint:
name: frankfurther_api
path: /v1/currencies
http_headers:
Authorization: "Bearer $FRANKFURT_API_KEY"

endpoints:
frankfurther_api:
endpoint: api.frankfurter.dev:443
protocol: https
endpoint: host.docker.internal:1122

tracing:
random_sampling: 100
Expand Down

0 comments on commit a0db504

Please sign in to comment.