MCPcopy
hub / github.com/algorithmicsuperintelligence/optillm / proxy_models

Function proxy_models

optillm/server.py:944–976  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

942
943@app.route('/v1/models', methods=['GET'])
944def proxy_models():
945 logger.info('Received request to /v1/models')
946 default_client, API_KEY = get_config()
947 try:
948 if server_config['base_url']:
949 client = OpenAI(api_key=API_KEY, base_url=server_config['base_url'])
950 # For external API, fetch models using the OpenAI client
951 models_response = client.models.list()
952 # Convert to dict format
953 models_data = {
954 "object": "list",
955 "data": [model.dict() for model in models_response.data]
956 }
957 else:
958 # For local inference, create a models response manually
959 current_model = server_config.get('model', 'gpt-3.5-turbo')
960 models_data = {
961 "object": "list",
962 "data": [
963 {
964 "id": current_model,
965 "object": "model",
966 "created": 1677610602,
967 "owned_by": "optillm"
968 }
969 ]
970 }
971
972 logger.debug('Models retrieved successfully')
973 return jsonify(models_data), 200
974 except Exception as e:
975 logger.error(f"Error fetching models: {str(e)}")
976 return jsonify({"error": f"Error fetching models: {str(e)}"}), 500
977
978@app.route('/health', methods=['GET'])
979def health():

Callers

nothing calls this directly

Calls 2

get_configFunction · 0.85
listMethod · 0.45

Tested by

no test coverage detected