Untitled
unknown
plain_text
2 years ago
2.9 kB
17
Indexable
Code-
import openai
from flask import jsonify,request,Flask,render_template,json
app = Flask(__name__)
app.app_context().push()
@app.route('/suggest_solution', methods=['GET', 'POST'])
def get_completion(prompt, model="gpt-3.5-turbo"):
openai.api_key = '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'
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0, # Adjust the temperature to control the randomness of the model's output
)
return response.choices[0].message["content"]
if request.method == 'POST' :
param_val=request.args.get('prompt')
response = get_completion(param_val)
print(response)
if __name__ == "__main__":
app.run(host='100.87.2.56', port=8894, threaded=True)
Error-
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Input In [26], in <cell line: 18>()
11 response = openai.ChatCompletion.create(
12 model=model,
13 messages=messages,
14 temperature=0, # Adjust the temperature to control the randomness of the model's output
15 )
16 return response.choices[0].message["content"]
---> 18 if request.method == 'POST' :
19 param_val=request.args.get('prompt')
20 response = get_completion(param_val)
File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/werkzeug/local.py:436, in _ProxyLookup.__get__(self, instance, owner)
433 return self
435 try:
--> 436 obj = instance._get_current_object()
437 except RuntimeError:
438 if self.fallback is None:
File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/werkzeug/local.py:565, in LocalProxy._get_current_object(self)
560 """Return the current object. This is useful if you want the real
561 object behind the proxy at a time for performance reasons or because
562 you want to pass the object into a different context.
563 """
564 if not hasattr(self.__local, "__release_local__"): # type: ignore
--> 565 return self.__local() # type: ignore
567 try:
568 return getattr(self.__local, self.__name) # type: ignore
File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/flask/globals.py:33, in _lookup_req_object(name)
31 top = _request_ctx_stack.top
32 if top is None:
---> 33 raise RuntimeError(_request_ctx_err_msg)
34 return getattr(top, name)
RuntimeError: Working outside of request context.
This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.
Editor is loading...