File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22"""The dashscope API model classes."""
33import collections
4+ import json
5+ import os
46import warnings
57from datetime import datetime
68from http import HTTPStatus
@@ -100,6 +102,25 @@ def __init__(
100102
101103 dashscope .base_http_api_url = base_http_api_url
102104
105+ # Load headers from environment variable if exists
106+ headers = os .getenv ("DASHSCOPE_API_HEADERS" )
107+ if headers :
108+ try :
109+ headers = json .loads (str (headers ))
110+ if not isinstance (headers , dict ):
111+ raise json .JSONDecodeError ("" , "" , 0 )
112+
113+ if self .generate_kwargs .get ("headers" ):
114+ headers .update (self .generate_kwargs ["headers" ])
115+
116+ self .generate_kwargs ["headers" ] = headers
117+
118+ except json .JSONDecodeError :
119+ logger .warning (
120+ "Failed to parse DASHSCOPE_API_HEADERS environment "
121+ "variable as JSON. It should be a JSON object." ,
122+ )
123+
103124 @trace_llm
104125 async def __call__ (
105126 self ,
You can’t perform that action at this time.
0 commit comments