qianfan.common.hub package
Submodules
qianfan.common.hub.hub module
Hub
- qianfan.common.hub.hub.load(src: Optional[str] = None, json_str: Optional[str] = None, path: Optional[str] = None, url: Optional[str] = None) Any[source]
Loads an object from either a JSON string, a file specified by its path, or a URL. ONLY ONE SOURCE SHOULD BE PROVIDED. When multiple sources are provided, which source will be used is undefined.
- Parameters:
- src (Optional[str]):
A str indicating the source on qianfan platform. The str should be in the format of <type>/<name>.
- json_str (Optional[str]):
A JSON-formatted string containing the serialized representation of the object, which is the return value of the hub.save method.
- path (Optional[str]):
The path to the file from which the object should be loaded.
- url (Optional[str]):
The URL from which the object should be loaded.
- Returns:
- Any:
The deserialized object.
Example: ```python # Example 1: Load from qianfan platform prompt = load(“prompt/my_prompt”)
# Example 2: Load from a JSON string data = save(obj) loaded_object = load(json_str=data)
# Example 3: Load from a file file_path = ‘path/to/data.json’ loaded_object = load(path=file_path)
# Example 4: Load from a URL url = ‘https://example.com/data.json’ loaded_object = load(url=url) ```
- qianfan.common.hub.hub.push(obj: Any) None[source]
Push the object to qianfan platform.
- Parameters:
- obj (HubSerializable):
The object to be pushed to qianfan platform.
- Returns:
None
- qianfan.common.hub.hub.save(obj: HubSerializable, to_platform: bool = False, path: Optional[str] = None, dump_args: Dict[str, Any] = {}) str[source]
Serialize the given object and save it to different sources.
This function takes an object (obj) that implements the HubSerializable interface and serializes it. The serialized data is then saved to a file specified by the optional path parameter. The serialization process can be customized further by providing additional arguments in the dump_args dictionary.
- Parameters:
- obj (HubSerializable):
The object to be serialized.
- to_platform (bool):
Whether to push the object to qianfan platform.
- path (Optional[str]):
The file path where the serialized data will be saved. If not provided, the serialized data is not saved to a file.
- dump_args (Dict[str, Any]):
Additional keyword arguments to customize the serialization result. These arguments are passed to json.dumps function.
- Returns:
- str:
The serialized result.
qianfan.common.hub.interface module
Hub Interface