Skip to content

Commit d70a685

Browse files
authored
Add model config (#72)
* Add model config Signed-off-by: kerthcet <kerthcet@gmail.com> * Add issue templates Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent 14ae4b1 commit d70a685

16 files changed

Lines changed: 347 additions & 1 deletion

File tree

.github/ISSUE_TEMPLATE/BUG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Bug Report
3+
about: Report a bug encountered while using
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks!
11+
-->
12+
13+
**What happened**:
14+
15+
**What you expected to happen**:
16+
17+
**How to reproduce it (as minimally and precisely as possible)**:
18+
19+
**Anything else we need to know?**:
20+
21+
**Environment**:

.github/ISSUE_TEMPLATE/CLEANUP.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Clean Up Request
3+
about: Suggest to clean up code, process or tech debt to the project
4+
title: ''
5+
labels: cleanup
6+
assignees: ''
7+
8+
---
9+
10+
<!-- Please only use this template for submitting clean up requests -->
11+
12+
**What would you like to be cleaned**:
13+
14+
**Why is this needed**:

.github/ISSUE_TEMPLATE/FEATURE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Feature Request
3+
about: Suggest a feature to the project
4+
title: ''
5+
labels: feature
6+
assignees: ''
7+
8+
---
9+
10+
<!-- Please only use this template for submitting feature requests -->
11+
12+
**What would you like to be added**:
13+
14+
**Why is this needed**:
15+
16+
**Completion requirements**:
17+
18+
This feature requires the following artifacts:
19+
20+
- [ ] Design doc
21+
- [ ] API change
22+
- [ ] Docs update
23+
24+
The artifacts should be linked in subsequent comments.

.github/ISSUE_TEMPLATE/RELEASE.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: New Release
3+
about: Propose a new release
4+
title: Release v0.x.0
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
## Release Checklist
11+
<!--
12+
Please do not remove items from the checklist
13+
-->
14+
- [ ] Verify that the changelog in this issue is up-to-date
15+
- [ ] Bump the version number in `pyproject.toml` to the new version (e.g., v0.x.0)
16+
- [ ] Merge the PR that bumps the version number
17+
- [ ] For major or minor releases (v$MAJ.$MIN.0), create a new release branch.
18+
- [ ] an OWNER creates a vanilla release branch with
19+
`git branch release-$MAJ.$MIN.0 main`
20+
- [ ] An OWNER pushes the new release branch with
21+
`git push --set-upstream upstream release-$MAJ.$MIN.0`
22+
- [ ] An OWNER [prepares a draft release](https://github.com/inftyai/amrs/releases)
23+
- [ ] Write the change log into the draft release.
24+
- [ ] Don't release the draft yet.
25+
- [ ] Publish the release to PyPI
26+
- [ ] run `make build` to build the package
27+
- [ ] run `make publish` to publish the package to PyPI
28+
- [ ] Publish the draft release prepared at the [Github releases page](https://github.com/inftyai/amrs/releases).
29+
- [ ] Close this issue
30+
31+
32+
## Changelog
33+
<!--
34+
Describe changes since the last release here.
35+
-->

.github/ISSUE_TEMPLATE/SUPPORT.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: Support Request
3+
about: Support request or question relating to the project
4+
title: ''
5+
labels: support
6+
assignees: ''
7+
8+
---

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#### What this PR does / why we need it
2+
3+
#### Which issue(s) this PR fixes
4+
<!--
5+
*Automatically closes linked issue when PR is merged.
6+
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
7+
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
8+
-->
9+
Fixes #
10+
11+
#### Special notes for your reviewer
12+
13+
#### Does this PR introduce a user-facing change?
14+
<!--
15+
If no, just write "NONE" in the release-note block below.
16+
If yes, a release note is required:
17+
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
18+
-->
19+
```release-note
20+
21+
```

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ __pycache__
1212
/temp/
1313

1414
dist/
15+
16+
17+
# Added by cargo
18+
19+
/target

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "AMRS"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]

amrs/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from amrs.config import ModelConfig, Config, RoutingMode
2+
3+
__all__ = [
4+
"ModelConfig",
5+
"Config",
6+
"RoutingMode",
7+
]

amrs/config.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from enum import Enum
2+
from typing import Callable
3+
from pydantic import BaseModel, Field, model_validator
4+
from typing import List, Optional
5+
6+
class BasicModelConfig(BaseModel):
7+
base_url: Optional[str] = Field(
8+
default=None,
9+
description="Global base URL for model API endpoints."
10+
)
11+
temperature: Optional[float] = Field(
12+
default=0.8,
13+
description="Global temperature setting for model generation."
14+
)
15+
16+
class ModelConfig(BasicModelConfig):
17+
id: str = Field(
18+
description="ID of the model, including both the provider name and the model name, e.g. 'openai:gpt-4'."
19+
)
20+
weight: Optional[int] = Field(
21+
default=1,
22+
description="Weight of the model for ensemble methods. Only used if routing_mode is 'weighted'."
23+
)
24+
25+
class ChatRole(str, Enum):
26+
USER = "user"
27+
ASSISTANT = "assistant"
28+
SYSTEM = "system"
29+
30+
class Message(BaseModel):
31+
role: ChatRole = Field(description="Role of the message sender.")
32+
# For image messages, the format is different, but we only support text message for now.
33+
# See https://platform.openai.com/docs/api-reference/chat/create
34+
content: str = Field(description="Content of the message.")
35+
36+
class RoutingMode(str, Enum):
37+
RANDOM = "random"
38+
WEIGHTED = "weighted"
39+
40+
class Config(BasicModelConfig):
41+
models: List[ModelConfig] = Field(description="List of model configurations")
42+
routing_mode: RoutingMode = Field(
43+
default=RoutingMode.RANDOM,
44+
description="Routing mode for the model, default is random.",
45+
)
46+
callback_funcs: Optional[List[Callable]] = Field(
47+
default=None,
48+
description="Callback functions to be called after each model inference. Functions will be called sequentially.",
49+
)
50+
messages: str | List[Message] = Field(
51+
description="Messages to be sent to the model(s). Can be a string or a list of Message objects."
52+
)
53+
54+
@model_validator(mode="after")
55+
def ensure_at_least_one_base_url(self):
56+
global_url_exist = self.base_url is not None
57+
58+
for model in self.models:
59+
if not model.base_url and not global_url_exist:
60+
raise ValueError("At least one base_url must be specified either in the global config or in each model config.")
61+
62+
return self

0 commit comments

Comments
 (0)