Skip to content

Commit a377312

Browse files
authored
Merge pull request #61 from cloudera/dev
Freeform endpoints for generation and evaluation. Bedrock Model discoverability with endpoint health check. Bug removal fopr model family detection. telemetry dashboard addded but commented for now
2 parents f6cb4df + 2a9a816 commit a377312

28 files changed

+3478
-259
lines changed

README.md

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,36 @@ Built using:
8484
```
8585

8686

87-
## Local development and testing
87+
##Aaccessing API endpoints directly.
8888

89-
1. To access the backend locally or in CLoudera environment, run the following bash command in your terminal.
90-
```bash
91-
92-
source .venv/bin/activate # On mac/Linux
93-
94-
.venv\Scripts\activate # On Windows
95-
python app/run_be.py
9689

97-
```
98-
2. This will start application on **http://0.0.0.0:8001**.
99-
3. To generate a sample for code generation you can use following code snippet
90+
1. To generate/synthesise a sample for code generation you can use following code snippet
10091
```python
101-
import requests
92+
import requests
93+
import os
94+
#********************Accessing Application**************************
95+
# Get API key from environment variable if withinin CDSW app/session.
96+
# To get your API key for using outside CDSW app/session follow given link.
97+
# https://docs.cloudera.com/machine-learning/cloud/api/topics/ml-api-v2.html
98+
api_key = os.environ.get('CDSW_APIV2_KEY')
99+
102100

103-
url = 'http://0.0.0.0:8001/synthesis/generate'
101+
# Below is your application API URL, you can look at swagger documentation
102+
# https://<application-subdomain>.<workbench-domain>/docs--> will take user to swagger documentaion
103+
# Link to application can be found on application details page within CAI Workbench.
104104

105+
106+
# URL for synthesis
107+
url = https://<application-subdomain>.<workbench-domain>/synthesis/generate'
108+
109+
# Add the API key to headers with proper Authorization format
105110
headers = {
106111
'accept': 'application/json',
107-
'Content-Type': 'application/json'
108-
}
112+
'Content-Type': 'application/json',
113+
'Authorization': f'Bearer {api_key}' # Format as specified in the documentation
114+
}
109115

116+
# Pyload for data synthesis.
110117
payload = {
111118
"use_case": "code_generation",
112119
"model_id": "us.anthropic.claude-3-5-haiku-20241022-v1:0",
@@ -122,7 +129,7 @@ payload = {
122129
},
123130
{
124131
"question": "How do you implement a stack using a list in Python?",
125-
"solution": "Here's how to implement a basic stack:\n\n```python\nclass Stack:\n def __init__(self):\n self.items = []\n \n def push(self, item):\n self.items.append(item)\n \n def pop(self):\n if not self.is_empty():\n return self.items.pop()\n \n def is_empty(self):\n return len(self.items) == 0\n```"
132+
"solution": "Here's how to implement a basic stack:\n\n```python\nclass Stack:\n def **init**(self):\n self.items = []\n \n def push(self, item):\n self.items.append(item)\n \n def pop(self):\n if not self.is_empty():\n return self.items.pop()\n \n def is_empty(self):\n return len(self.items) == 0\n```"
126133
}
127134
],
128135
"model_params": {
@@ -133,25 +140,39 @@ payload = {
133140
}
134141
}
135142

136-
response = requests.post(url, headers=headers, json=payload)
143+
# Add error handling to check if API key exists
144+
if not api_key:
145+
print("Warning:No API key provided")
137146

138-
# Print the response
139-
print(response.status_code)
140-
print(response.json())
141147

142148
```
143149

144-
4. If you want to evaluate then you can se following code snippet. Make sure to use correct **input_path**.
150+
2. If you want to evaluate then you can se following code snippet. Make sure to use correct **import_path**.
145151
```python
146152

147153
import requests
154+
import os
155+
#********************Accessing Application**************************
156+
# Get API key from environment variable if withinin CDSW app/session.
157+
# To get your API key for using outside CDSW app/session follow given link.
158+
# https://docs.cloudera.com/machine-learning/cloud/api/topics/ml-api-v2.html
159+
api_key = os.environ.get('CDSW_APIV2_KEY')
160+
148161

149-
url = 'http://0.0.0.0:8001/synthesis/evaluate'
162+
# Below is your application API URL, you can look at swagger documentation for all existing # endpoints for current application
163+
# https://<application-subdomain>.<workbench-domain>/docs--> will take user to swagger documentaion
164+
# Link to application can be found on application details page within CAI Workbench.
150165

166+
167+
# URL for evaluation
168+
url = https://<application-subdomain>.<workbench-domain>/synthesis/evaluate'
169+
170+
# Add the API key to headers with proper Authorization format
151171
headers = {
152172
'accept': 'application/json',
153-
'Content-Type': 'application/json'
154-
}
173+
'Content-Type': 'application/json',
174+
'Authorization': f'Bearer {api_key}' # Format as specified in the documentation
175+
}
155176

156177
# The prompt for evaluation
157178
custom_prompt = """Below is a Python coding Question and Solution pair generated by an LLM. Evaluate its quality as a Senior Developer would, considering its suitability for professional use. Use the additive 5-point scoring system described below.

app/client/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
"@mui/material": "6.1.7",
1818
"@tanstack/react-query": "5.66.0",
1919
"antd": "5.22.1",
20+
"axios": "1.6.7",
2021
"lodash": "4.17.21",
2122
"moment": "2.30.1",
2223
"react": "18.3.1",
2324
"react-dom": "18.3.1",
2425
"react-markdown": "9.0.1",
2526
"react-router-dom": "6.28.0",
2627
"react-syntax-highlighter": "15.5.0",
27-
"styled-components": "6.1.13"
28+
"styled-components": "6.1.13",
29+
"recharts": "2.12.2"
2830
},
2931
"devDependencies": {
3032
"@eslint/js": "9.13.0",

app/client/src/Container.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const pages: MenuItem[] = [
7171
<Link to={`${Pages.GENERATOR}`}>{LABELS[Pages.GENERATOR]}</Link>
7272
),
7373
},
74+
// {
75+
// key: Pages.TELEMETRY,
76+
// label: (
77+
// <Link to={`${Pages.TELEMETRY}`}>{LABELS[Pages.TELEMETRY]}</Link>
78+
// ),
79+
// },
7480
{
7581
key: Pages.FEEDBACK,
7682
label: (

0 commit comments

Comments
 (0)