generated from konveyor-ecosystem/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update pydantic notebook to output results/traceback to file
Signed-off-by: Jason Montleon <jmontleo@redhat.com>
- Loading branch information
Showing
92 changed files
with
9,940 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../jms_to_smallrye_reactive/analysis_report |
131 changes: 131 additions & 0 deletions
131
notebooks/pydantic/jms_to_smallrye_reactive/caikit_tgis_langchain.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
from typing import Any, Iterator, List, Mapping, Optional, Union | ||
from warnings import warn | ||
|
||
from caikit_nlp_client import GrpcClient, HttpClient | ||
from langchain.callbacks.manager import CallbackManagerForLLMRun | ||
from langchain.llms.base import LLM | ||
from langchain.schema.output import GenerationChunk | ||
|
||
|
||
class CaikitLLM(LLM): | ||
inference_server_url: str | ||
model_id: str | ||
certificate_chain: Optional[str] = None | ||
streaming: bool | ||
client: HttpClient | ||
|
||
def __init__( | ||
self, | ||
inference_server_url: str, | ||
model_id: str, | ||
certificate_chain: Optional[str] = None, | ||
streaming: bool = False, | ||
client: Optional[GrpcClient] = HttpClient(""), | ||
): | ||
super().__init__( | ||
inference_server_url=inference_server_url, | ||
model_id=model_id, | ||
certificate_chain=certificate_chain, | ||
streaming=streaming, | ||
client=client, | ||
) | ||
|
||
self.inference_server_url = inference_server_url | ||
self.model_id = model_id | ||
|
||
if certificate_chain: | ||
with open(certificate_chain, "rb") as fh: | ||
chain = fh.read() | ||
else: | ||
chain = None | ||
|
||
if inference_server_url.startswith("http"): | ||
client = HttpClient(inference_server_url) | ||
else: | ||
try: | ||
host, port = inference_server_url.split(":") | ||
if not all((host, port)): | ||
raise ValueError | ||
except ValueError: | ||
raise ValueError( | ||
"Invalid url provided, must be either " | ||
'"host:port" or "http[s]://host:port/path"' | ||
) | ||
|
||
client = GrpcClient(host, port, ca_cert=chain) | ||
|
||
self.client: Union[HttpClient, GrpcClient] = client | ||
|
||
@property | ||
def _llm_type(self) -> str: | ||
return "caikit_tgis" | ||
|
||
def _call( | ||
self, | ||
prompt: str, | ||
preserve_input_text: bool = False, | ||
max_new_tokens: int = 512, | ||
min_new_tokens: int = 10, | ||
device: str = "", | ||
stop: Optional[List[str]] = None, | ||
run_manager: Optional[CallbackManagerForLLMRun] = None, | ||
**kwargs: Any, | ||
) -> str: | ||
if self.streaming: | ||
return "".join( | ||
self._stream( | ||
prompt=prompt, | ||
preserve_input_text=preserve_input_text, | ||
max_new_tokens=max_new_tokens, | ||
min_new_tokens=min_new_tokens, | ||
device=device, | ||
stop=stop, | ||
run_manager=run_manager, | ||
**kwargs, | ||
) | ||
) | ||
if run_manager: | ||
warn("run_manager is ignored for non-streaming use cases") | ||
|
||
if device or stop: | ||
raise NotImplementedError() | ||
|
||
return self.client.generate_text( | ||
self.model_id, | ||
prompt, | ||
preserve_input_text=preserve_input_text, | ||
max_new_tokens=max_new_tokens, | ||
min_new_tokens=min_new_tokens, | ||
) | ||
|
||
def _stream( | ||
self, | ||
prompt: str, | ||
preserve_input_text: bool = False, | ||
max_new_tokens: int = 512, | ||
min_new_tokens: int = 10, | ||
device: str = "", | ||
stop: Optional[List[str]] = None, | ||
run_manager: Optional[CallbackManagerForLLMRun] = None, | ||
**kwargs: Any, | ||
) -> Iterator[GenerationChunk]: | ||
if device or stop: | ||
raise NotImplementedError | ||
|
||
for token in self.client.generate_text_stream( | ||
self.model_id, | ||
prompt, | ||
preserve_input_text=preserve_input_text, | ||
max_new_tokens=max_new_tokens, | ||
min_new_tokens=min_new_tokens, | ||
): | ||
chunk = GenerationChunk(text=token) | ||
yield chunk.text | ||
|
||
if run_manager: | ||
run_manager.on_llm_new_token(chunk.text) | ||
|
||
@property | ||
def _identifying_params(self) -> Mapping[str, Any]: | ||
"""Get the identifying parameters.""" | ||
return {"inference_server_url": self.inference_server_url} |
58 changes: 58 additions & 0 deletions
58
...reactive/output/ibm_codellama_codellama-34b-instruct/few_shot_pydantic/original_file.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.as.quickstarts.mdb; | ||
|
||
import java.util.logging.Logger; | ||
import javax.ejb.ActivationConfigProperty; | ||
import javax.ejb.MessageDriven; | ||
import javax.jms.JMSException; | ||
import javax.jms.Message; | ||
import javax.jms.MessageListener; | ||
import javax.jms.TextMessage; | ||
|
||
/** | ||
* <p> | ||
* A simple Message Driven Bean that asynchronously receives and processes the messages that are sent to the queue. | ||
* </p> | ||
* | ||
* @author Serge Pagop (spagop@redhat.com) | ||
*/ | ||
@MessageDriven(name = "HelloWorldQueueMDB", activationConfig = { | ||
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "queue/HELLOWORLDMDBQueue"), | ||
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), | ||
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")}) | ||
public class HelloWorldQueueMDB implements MessageListener { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(HelloWorldQueueMDB.class.toString()); | ||
|
||
/** | ||
* @see MessageListener#onMessage(Message) | ||
*/ | ||
public void onMessage(Message rcvMessage) { | ||
TextMessage msg = null; | ||
try { | ||
if (rcvMessage instanceof TextMessage) { | ||
msg = (TextMessage) rcvMessage; | ||
LOGGER.info("Received Message from queue: " + msg.getText()); | ||
} else { | ||
LOGGER.warning("Message of wrong type: " + rcvMessage.getClass().getName()); | ||
} | ||
} catch (JMSException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...tput/ibm_codellama_codellama-34b-instruct/few_shot_pydantic/quarkus_version_from_git.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.as.quickstarts.mdb; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import io.smallrye.reactive.messaging.annotations.Merge; | ||
import org.jboss.logging.Logger; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
|
||
@ApplicationScoped | ||
public class HelloWorldQueueMDB { | ||
private static final Logger LOGGER = Logger.getLogger(HelloWorldQueueMDB.class.toString()); | ||
|
||
@Incoming("HELLOWORLDMDBQueue") | ||
@Merge | ||
public void onMessage(String message) { | ||
LOGGER.info("Received Message from queue: " + message); | ||
} | ||
} |
Oops, something went wrong.