Spaces:
Sleeping
Sleeping
File size: 2,749 Bytes
3e68ccf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
from global_config import GlobalConfig
######################################################################################################
# In this section, we set the user authentication, user and app ID, model details, and the URL of
# the text we want as an input. Change these strings to run your own example.
######################################################################################################
TEXT_FILE_URL = 'https://samples.clarifai.com/negative_sentence_12.txt'
############################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
############################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (
('authorization', 'Key ' + GlobalConfig.CLARIFAI_PAT),
# ('temp', '0.9'), # Does not work
)
userDataObject = resources_pb2.UserAppIDSet(
user_id=GlobalConfig.CLARIFAI_USER_ID,
app_id=GlobalConfig.CLARIFAI_APP_ID
)
RAW_TEXT = '''You are a helpful, intelligent chatbot.
Create the slides for a presentation on the given topic.
Include main headings for each slide, detailed bullet points for each slide.
Add relevant content to each slide.
The output should be complete, coherent, and have maximum 255 tokens.
Topic:
Talk about AI, covering what it is and how it works. Add its pros, cons, and future prospects. Also, cover its job prospects.
'''
post_model_outputs_response = stub.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
model_id=GlobalConfig.CLARIFAI_MODEL_ID,
# version_id=MODEL_VERSION_ID, # This is optional. Defaults to the latest model version
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
text=resources_pb2.Text(
# url=TEXT_FILE_URL,
raw=RAW_TEXT
)
)
)
]
),
metadata=metadata
)
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
print(post_model_outputs_response.status)
raise Exception(f"Post model outputs failed, status: {post_model_outputs_response.status.description}")
# Since we have one input, one output will exist here
output = post_model_outputs_response.outputs[0]
print("Completion:\n")
print(output.data.text.raw)
|