@@ -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\S cripts\a ctivate # 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
105110headers = {
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.
110117payload = {
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\n class 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\n class 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
147153import 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
151171headers = {
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
157178custom_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.
0 commit comments