Skip to content

Commit

Permalink
Create update_model endpoint
Browse files Browse the repository at this point in the history
TSIA, backend implementation of `update_model()`. The other changes were from running the auto-formatter:
```
fd --glob '*.py'  python/src/aiconfig/editor/server | xargs python -m 'scripts.lint' --mode=fix --files
```

## Test Plan
Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command
```
curl http://localhost:8080/api/update_model -d curl http://localhost:8080/api/update_model -d '{"prompt_name":"get_activities", "model_name": "gpt-4", "settings": {"top_p": 0.9}}' -X POST -H 'Content-Type: application/json'
```
Notice that the model name is updated to `gpt-4`, and the `top_p` is now at 0.9

https://github.com/lastmile-ai/aiconfig/assets/151060367/3031fa59-8925-495c-a5eb-e56ec65b7fba
  • Loading branch information
Rossdan Craig [email protected] committed Jan 2, 2024
1 parent d59c29e commit 09ba906
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 16 additions & 1 deletion python/src/aiconfig/editor/server/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Type
from typing import Any, Dict, Type

import lastmile_utils.lib.core.api as core_utils
import result
Expand Down Expand Up @@ -226,3 +226,18 @@ def delete_prompt() -> FlaskResponse:

operation = make_op_run_method(method_name)
return run_aiconfig_operation_with_request_json(aiconfig, request_json, f"method_{method_name}", operation, signature)


@app.route("/api/update_model", methods=["POST"])
def update_model() -> FlaskResponse:
state = get_server_state(app)
aiconfig = state.aiconfig
request_json = request.get_json()

model_name: str | None = request_json.get("model_name")
settings: Dict[str, Any] | None = request_json.get("settings")
prompt_name: str | None = request_json.get("prompt_name")

operation = make_op_run_method(MethodName("update_model"))
operation_args: Result[OpArgs, str] = result.Ok(OpArgs({"model_name": model_name, "settings": settings, "prompt_name": prompt_name}))
return run_aiconfig_operation_with_op_args(aiconfig, "update_model", operation, operation_args)
5 changes: 3 additions & 2 deletions python/src/aiconfig/editor/server/server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
from enum import Enum
from types import ModuleType
from typing import Any, Callable, NewType, Optional, Type, TypeVar, cast
from aiconfig.registry import ModelParserRegistry
from aiconfig.schema import Prompt, PromptMetadata

import lastmile_utils.lib.core.api as core_utils
import result
from aiconfig.Config import AIConfigRuntime
from aiconfig.registry import ModelParserRegistry
from flask import Flask
from pydantic import field_validator
from result import Err, Ok, Result

from aiconfig.schema import Prompt, PromptMetadata

MethodName = NewType("MethodName", str)

logging.getLogger("werkzeug").disabled = True
Expand Down

0 comments on commit 09ba906

Please sign in to comment.