Skip to content

Commit c5006da

Browse files
authored
Merge pull request #49 from SAP/develop
Release v0.2.1
2 parents 1c711da + dbce5b1 commit c5006da

11 files changed

Lines changed: 8415 additions & 7874 deletions

File tree

.github/workflows/lint-frontend.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ jobs:
3535
npm ci
3636
3737
- name: Run linters
38-
uses: wearerequired/lint-action@v2
38+
uses: reviewdog/action-eslint@v1
3939
with:
40-
eslint: true
41-
eslint_dir: frontend
42-
eslint_extensions: js,ts
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
reporter: github-pr-review
42+
eslint_flags: 'frontend/'
43+
fail_on_error: true
44+
level: warning

.reuse/dep5

Lines changed: 0 additions & 50 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Version: v0.2.1
2+
3+
* [#34](https://github.com/SAP/STARS/pull/34): Support aicore-mistralai models
4+
* [#36](https://github.com/SAP/STARS/pull/36): Fix/frontend
5+
* [#37](https://github.com/SAP/STARS/pull/37): Bump prismjs from 1.29.0 to 1.30.0 in /frontend
6+
* [#39](https://github.com/SAP/STARS/pull/39): Support remote ollama models
7+
* [#40](https://github.com/SAP/STARS/pull/40): [chore]:Reuse API update - Migration from dep5 file to TOML file.
8+
* [#47](https://github.com/SAP/STARS/pull/47): Bump flask-cors from 5.0.0 to 6.0.0 in /backend-agent
9+
* [#48](https://github.com/SAP/STARS/pull/48): Fix js linter action
10+
11+
112
# Version: v0.2.0
213

314
* [#25](https://github.com/SAP/STARS/pull/25): Bump katex from 0.16.10 to 0.16.21 in /frontend

REUSE.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version = 1
2+
SPDX-PackageName = "Smart Threat AI Reporting Scanner (STARS)"
3+
SPDX-PackageSupplier = "ospo@sap.com"
4+
SPDX-PackageDownloadLocation = "https://github.com/SAP/stars"
5+
SPDX-PackageComment = "The code in this project may include calls to APIs (\"API Calls\") of\n SAP or third-party products or services developed outside of this project\n (\"External Products\").\n \"APIs\" means application programming interfaces, as well as their respective\n specifications and implementing code that allows software to communicate with\n other software.\n API Calls to External Products are not licensed under the open source license\n that governs this project. The use of such API Calls and related External\n Products are subject to applicable additional agreements with the relevant\n provider of the External Products. In no event shall the open source license\n that governs this project grant any rights in or to any External Products,or\n alter, expand or supersede any terms of the applicable additional agreements.\n If you have a valid license agreement with SAP for the use of a particular SAP\n External Product, then you may make use of any API Calls included in this\n project's code for that SAP External Product, subject to the terms of such\n license agreement. If you do not have a valid license agreement for the use of\n a particular SAP External Product, then you may only make use of any API Calls\n in this project for that SAP External Product for your internal, non-productive\n and non-commercial test and evaluation of such API Calls. Nothing herein grants\n you any rights to use or access any SAP External Product, or provide any third\n parties the right to use of access any SAP External Product, through API Calls."
6+
7+
[[annotations]]
8+
path = "**"
9+
precedence = "aggregate"
10+
SPDX-FileCopyrightText = "2024 SAP SE or an SAP affiliate company and stars contributors"
11+
SPDX-License-Identifier = "Apache-2.0"
12+
13+
[[annotations]]
14+
path = "backend-agent/cli.py"
15+
precedence = "aggregate"
16+
SPDX-FileCopyrightText = ["", "2024 SAP SE or an SAP affiliate company and STARS contributors", "2021 Sandflow Consulting LLC"]
17+
SPDX-License-Identifier = "Apache-2.0 and BSD-3-Clause"
18+
SPDX-FileComment = "these files contain content from SAP and ttconv: cli.py is overall written by SAP, but contains a code snippet from src/main/python/ttconv/tt.py file taken from ttconv"
19+
20+
[[annotations]]
21+
path = "backend-agent/libs/artprompt.py"
22+
precedence = "aggregate"
23+
SPDX-FileCopyrightText = ["", "2024 SAP SE or an SAP affiliate company and STARS contributors", "2024 UW-NSL"]
24+
SPDX-License-Identifier = "Apache-2.0 and MIT"
25+
SPDX-FileComment = "these files contain content from SAP and UW-NSL: the original content was written by UW-NSL, but it was refactored, simplified, and modified by SAP to be more suitable to this project"
26+
27+
[[annotations]]
28+
path = "frontend/src/app/app.component.spec.ts"
29+
precedence = "aggregate"
30+
SPDX-FileCopyrightText = ["", "2010-2020 Google LLC. https://angular.io/license"]
31+
SPDX-License-Identifier = "MIT"
32+
SPDX-FileComment = "these files contain content from Angular 11.1.0-next.1 (it contains a code snippet from integration/trusted-types/src/app/app.component.spec.ts file taken from angular)"

backend-agent/llm.py

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,21 @@
2323
logger.addHandler(status.trace_logging)
2424

2525
AICORE_MODELS = {
26-
'openai':
26+
'aicore-ibm':
2727
[
28-
'gpt-35-turbo',
29-
'gpt-35-turbo-0125',
30-
'gpt-35-turbo-16k',
31-
'gpt-4',
32-
'gpt-4-32k',
33-
'gpt-4o',
34-
'gpt-4o-mini'
28+
'ibm--granite-13b-chat'
29+
],
30+
'aicore-mistralai':
31+
[
32+
'mistralai--mistral-large-instruct',
3533
],
36-
'opensource':
34+
'aicore-opensource':
3735
[
3836
'mistralai--mixtral-8x7b-instruct-v01',
3937
'meta--llama3.1-70b-instruct',
4038
'meta--llama3-70b-instruct'
4139
],
42-
'vertexai':
43-
[
44-
'text-bison',
45-
'chat-bison',
46-
'gemini-1.0-pro',
47-
'gemini-1.5-pro',
48-
'gemini-1.5-flash'
49-
],
50-
'ibm':
51-
[
52-
'ibm--granite-13b-chat'
53-
],
54-
'bedrock':
40+
'aws-bedrock':
5541
[
5642
'amazon--titan-text-lite',
5743
'amazon--titan-text-express',
@@ -62,7 +48,25 @@
6248
'amazon--nova-pro',
6349
'amazon--nova-lite',
6450
'amazon--nova-micro'
65-
]
51+
],
52+
'azure-openai':
53+
[
54+
'gpt-35-turbo',
55+
'gpt-35-turbo-0125',
56+
'gpt-35-turbo-16k',
57+
'gpt-4',
58+
'gpt-4-32k',
59+
'gpt-4o',
60+
'gpt-4o-mini'
61+
],
62+
'gcp-vertexai':
63+
[
64+
'text-bison',
65+
'chat-bison',
66+
'gemini-1.0-pro',
67+
'gemini-1.5-pro',
68+
'gemini-1.5-flash'
69+
],
6670
}
6771

6872

@@ -79,25 +83,30 @@ def from_model_name(cls, model_name: str) -> 'LLM':
7983
Create a specific LLM object from the name of the model.
8084
Useful because the user can specify only the name in the agent.
8185
"""
82-
if 'gpt' in model_name:
86+
# Foundation-models scenarios in AI Core
87+
if model_name in AICORE_MODELS['azure-openai']:
8388
# The agent sometimes autocorrects gpt-35-turbo to gpt-3.5-turbo,
8489
# so we handle this behavior here.
8590
if model_name == 'gpt-3.5-turbo':
8691
model_name = 'gpt-35-turbo'
8792
return AICoreOpenAILLM(model_name)
88-
if model_name in AICORE_MODELS['opensource']:
89-
return AICoreOpenAILLM(model_name, False)
90-
if model_name in AICORE_MODELS['ibm']:
93+
if model_name in AICORE_MODELS['aicore-ibm']:
9194
# IBM models are compatible with OpenAI completion API
9295
return AICoreOpenAILLM(model_name)
93-
if model_name in AICORE_MODELS['vertexai']:
94-
return AICoreGoogleVertexLLM(model_name)
95-
if model_name in AICORE_MODELS['bedrock']:
96+
if model_name in AICORE_MODELS['aicore-opensource']:
97+
return AICoreOpenAILLM(model_name, False)
98+
if model_name in AICORE_MODELS['aicore-mistralai']:
99+
return AICoreOpenAILLM(model_name, False)
100+
if model_name in AICORE_MODELS['aws-bedrock']:
96101
if 'titan' in model_name:
97102
# Titan models don't support system prompts
98103
return AICoreAmazonBedrockLLM(model_name, False)
99104
else:
100105
return AICoreAmazonBedrockLLM(model_name)
106+
if model_name in AICORE_MODELS['gcp-vertexai']:
107+
return AICoreGoogleVertexLLM(model_name)
108+
109+
# Custom models
101110
if model_name == 'mistral':
102111
return LocalOpenAILLM(
103112
os.getenv('MISTRAL_MODEL_NAME', ''),
@@ -109,9 +118,17 @@ def from_model_name(cls, model_name: str) -> 'LLM':
109118
# possible local ollama instance. If it not even served there, then an
110119
# exception is raised because such model has either an incorrect name
111120
# or it has not been deployed.
121+
ollama_host = os.getenv('OLLAMA_HOST')
122+
ollama_port = os.getenv('OLLAMA_PORT', 11434)
112123
try:
113-
ollama.show(model_name)
114-
return OllamaLLM(model_name)
124+
if ollama_host:
125+
# The model is served in a remote ollama instance
126+
remote_ollama_host = f'{ollama_host}:{ollama_port}'
127+
return OllamaLLM(model_name, remote_ollama_host)
128+
else:
129+
# The model is served in a local ollama instance
130+
ollama.show(model_name)
131+
return OllamaLLM(model_name)
115132
except (ollama.ResponseError, httpx.ConnectError):
116133
raise ValueError(f'Model {model_name} not found')
117134

@@ -127,7 +144,17 @@ def _calculate_list_of_supported_models(self) -> list[str]:
127144
if os.getenv('MISTRAL_URL'):
128145
models.append('mistral')
129146
try:
130-
ollama_models = [m['name'] for m in ollama.list()['models']]
147+
ollama_models = []
148+
ollama_host = os.getenv('OLLAMA_HOST')
149+
ollama_port = os.getenv('OLLAMA_PORT', 11434)
150+
if ollama_host:
151+
# The model is served in a remote ollama instance
152+
remote_ollama_host = f'{ollama_host}:{ollama_port}'
153+
ollama_models = [m['model'] for m in
154+
ollama.Client(remote_ollama_host).list()
155+
['models']]
156+
else:
157+
ollama_models = [m['name'] for m in ollama.list()['models']]
131158
return models + ollama_models
132159
except httpx.ConnectError:
133160
return models
@@ -325,28 +352,30 @@ def generate_completions_for_messages(self,
325352

326353

327354
class OllamaLLM(LLM):
328-
def __init__(self, model_name: str):
355+
def __init__(self, model_name: str, host=None):
329356
self.model_name = model_name
357+
self.client = ollama.Client(host=host)
330358

331359
def __str__(self) -> str:
332360
return f'{self.model_name}/Ollama LLM'
333361

334362
def generate(self,
335363
system_prompt: str,
336364
prompt: str,
337-
temperature: float,
338-
max_tokens: int,
339-
n: int) -> list[str]:
365+
max_tokens: int = 4096,
366+
temperature: float = 0.3,
367+
n: int = 1,) -> list[str]:
340368
try:
341369
messages = [
342370
{'role': 'system', 'content': system_prompt},
343371
{'role': 'user', 'content': prompt},
344372
]
345373
generations = [
346-
ollama.generate(self.model_name,
347-
prompt, system_prompt,
348-
options={'temperature': temperature})
349-
['response']
374+
self.client.generate(model=self.model_name,
375+
prompt=prompt,
376+
system=system_prompt,
377+
options={'temperature': temperature}
378+
)['response']
350379
for _ in range(n)]
351380
return self._trace_llm_call(messages, Success(generations))
352381
except Exception as e:
@@ -363,13 +392,14 @@ def generate_completions_for_messages(
363392
n: int = 1) -> list[str]:
364393
try:
365394
generations = [
366-
ollama.chat(self.model_name,
367-
messages,
368-
options={'temperature': temperature,
369-
'top_p': top_p,
370-
'frequency_penalty': frequency_penalty,
371-
'presence_penalty': presence_penalty})
372-
['message']['content']
395+
self.client.chat(
396+
self.model_name,
397+
messages,
398+
options={'temperature': temperature,
399+
'top_p': top_p,
400+
'frequency_penalty': frequency_penalty,
401+
'presence_penalty': presence_penalty}
402+
)['message']['content']
373403
for _ in range(n)
374404
]
375405
return self._trace_llm_call(messages, Success(generations))

backend-agent/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Deprecated==1.2.15
33
python-dotenv==1.0.1
44
faiss-cpu~=1.9.0
55
Flask==2.3.3
6-
Flask-Cors==5.0.0
6+
Flask-Cors==6.0.0
77
flask_sock==0.7.0
88
langchain~=0.2.16
99
PyYAML==6.0.2
@@ -17,7 +17,7 @@ tensorflow-hub
1717
sentence-transformers
1818
torchfile
1919
tensorflow-text
20-
ollama==0.4.2
20+
ollama==0.4.7
2121
weasyprint
2222
pyrit==0.2.1
2323
textattack>=0.3.10

0 commit comments

Comments
 (0)